Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. #Question3
  2. import random
  3.  
  4. print("Maths Challenge")
  5. print("Type e and any time to exit\n")
  6.  
  7. def subtraction():
  8.  
  9. global ans
  10. rights = 0
  11. wrongs = 0
  12.  
  13. question=random.randint(1,3)
  14. if(question==1):
  15. numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
  16. ans=input(str(numberOne) +" - " +str(numberTwo)+" = __" + "\nAnswer: ")
  17. if (str(ans)=='e' or str(ans)=='E'):
  18. print("Thanks you for using Math Challenge program")
  19. print("Number of rights: {0}".format(rights))
  20. print("Number of wrongs: {0}".format(wrongs))
  21. quit()
  22.  
  23. else:
  24. ans_int=int(ans)
  25. ans1= (numberOne - numberTwo)
  26. while (ans!=e):
  27. if (ans_int != ans1):
  28. print ("Wrong")
  29. wrongs=wrongs+1
  30. else:
  31. print("Correct")
  32. right=rights+1
  33. elif(question==2):
  34. numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
  35. ans=input(str(numberOne) + " - __ = " + str(numberTwo)+ "\nAnswer: ")
  36. if (str(ans)=='e' or str(ans)=='E'):
  37. print("Thanks you for using Math Challenge program")
  38. quit()
  39. else:
  40. ans_int=int(ans)
  41. ans1=(numberOne - numberTwo)
  42. while (ans!=e):
  43. if (ans_int != ans1):
  44. print ("Wrong")
  45. wrongs=wrongs+1
  46. else:
  47. print("Correct")
  48. right=rights+1
  49. elif(question==3):
  50. numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
  51. ans=input("__ - "+ str(numberOne) + " = "+ str(numberTwo)+ "\nAnswer: ")
  52. if (str(ans)=='e' or str(ans)=='E'):
  53. print("Thanks you for using Math Challenge program")
  54. quit()
  55. else:
  56. ans_int=int(ans)
  57. ans1=(numberTwo + numberOne)
  58. if (ans_int != ans1):
  59. print ("Wrong")
  60. wrongs=wrongs+1
  61. else:
  62. print("Correct")
  63. right=rights+1
  64. return ans
  65.  
  66. def addition():
  67. global ans
  68.  
  69. rights = 0
  70. wrongs = 0
  71.  
  72. question=random.randint(1,3)
  73. if(question==1):
  74. numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
  75. ans=input(str(numberOne) +" + " +str(numberTwo)+" = __" + "\nAnswer: ")
  76. if (str(ans)=='e' or str(ans)=='E'):
  77. print("Thanks you for using Math Challenge program")
  78. quit()
  79. else:
  80. ans_int=int(ans)
  81. ans1= (numberOne + numberTwo)
  82. if (ans_int != ans1):
  83. print ("Wrong")
  84. wrongs=wrongs+1
  85. else:
  86. print("Correct")
  87. right=rights+1
  88.  
  89. if(question==2):
  90. numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
  91. ans=input(str(numberOne) + " + __ = " + str(numberTwo)+ "\nAnswer: ")
  92. if (str(ans)=='e' or str(ans)=='E'):
  93. print("Thanks you for using Math Challenge program")
  94. quit()
  95. else:
  96. ans_int=int(ans)
  97. ans1= (numberTwo - numberOne)
  98. if (ans_int != ans1):
  99. print ("Wrong")
  100. wrongs=wrongs+1
  101. else:
  102. print("Correct")
  103. right=rights+1
  104.  
  105. if(question==3):
  106. numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
  107. ans=input("__ + "+ str(numberOne) + " = "+ str(numberTwo)+ "\nAnswer: ")
  108. if (str(ans)=='e' or str(ans)=='E'):
  109. print("Thanks you for using Math Challenge program")
  110. quit()
  111. else:
  112. ans_int=int(ans)
  113. ans1= (numberTwo - numberOne)
  114. if (ans_int != ans1):
  115. print ("Wrong")
  116. wrongs=wrongs+1
  117. else:
  118. print("Correct")
  119. right=rights+1
  120. return ans
  121.  
  122. print(ans)
  123. type_of_question= random.randint(1,2)
  124. if(type_of_question==1):
  125. print(subtraction())
  126. else:
  127. print(addition())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement