Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. import random
  2. USER_SCORE = 0
  3. questions = 0
  4. classnumber = ("1","2","3")
  5. name1= input("Enter Your Username: ")
  6. print("Hello, " , name1)
  7. print(" Welcome to the Arithmetic Quiz")
  8.  
  9. classno = input("What class are you in?")
  10. while classno not in classnumber:
  11. print("Enter a valid class")
  12. print("ENTER ONLY THE NUMBER n\ 1 n\ 2 n\3")
  13. classno=input("What class are you in?")
  14.  
  15. while questions <10:
  16. for i in range(10):
  17. num1=random.randint(1,10)
  18. num2=random.randint(1,10)
  19. on=random.choice("*-+")
  20. multiply=num1*num2
  21. subtract=num1-num2
  22. addition=num1+num2
  23.  
  24. if on == "-":
  25. print("MAKE SURE YOU ENTER A NUMBER OTHERWISE YOU WILL BE MARKED DOWN")
  26. questions+=1
  27. print(" Question" ,questions, "/10")
  28. uinput=input(str(num1)+" - "+str(num2))
  29. if uinput == str(subtract):
  30. USER_SCORE+=1
  31. print(" Correct, your USER_SCORE is: " ,USER_SCORE,)
  32. else:
  33. print (" Incorrect, the answer is: " +str(subtract))
  34. USER_SCORE+=0
  35.  
  36. if on == "+":
  37. print("MAKE SURE YOU ENTER A NUMBER OTHERWISE YOU WILL BE MARKED DOWN")
  38. questions+=1
  39. print(" Question",questions, "/10")
  40. uinput=input(str(num1)+" + "+str(num2))
  41. if uinput == str(addition):
  42. USER_SCORE+=1
  43. print(" Correct, your USER_SCORE is: ",USER_SCORE,)
  44. else:
  45. print(" Incorrect, the answer is: " +str(addition))
  46. USER_SCORE+=0
  47.  
  48. if on == "*":
  49. print("MAKE SURE YOU ENTER A NUMBER OTHERWISE YOU WILL BE MARKED DOWN")
  50. questions+=1
  51. print(" Question",questions, "/10")
  52. uinput=input(str(num1)+" * "+str(num2))
  53. if uinput == str(multiply):
  54. USER_SCORE+=1
  55. print(" Correct, your USER_SCORE is: " ,USER_SCORE,)
  56. else:
  57. print(" Incorrect, the answer is: " +str(multiply))
  58. USER_SCORE+=0
  59.  
  60. if USER_SCORE >9:
  61. print("Well done," ,name1, "your score is" ,USER_SCORE, "/10")
  62. else:
  63. print(name1," your score is " ,USER_SCORE, "/10")
  64.  
  65. def no1():
  66. with open("no1.txt", 'a')as file:
  67. file.write(str(name1)+" achieved a score of: "+str(USER_SCORE)+"/10 \n")
  68. def no2():
  69. with open("no2.txt", 'a')as file:
  70. file.write(str(name1)+" achieved a score of "+str(USER_SCORE)+"/10 \n")
  71. def no3():
  72. with open("no3.txt", 'a')as file:
  73. file.write(str(name1)+" achieved a score of "+str(USER_SCORE)+"/10 \n")
  74. if classno=="1":
  75. no1()
  76. if classno=="2":
  77. no2()
  78. if classno=="3":
  79. no3()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement