Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Question3
- import random
- print("Maths Challenge")
- print("Type e and any time to exit\n")
- def subtraction():
- global ans
- rights = 0
- wrongs = 0
- question=random.randint(1,3)
- if(question==1):
- numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
- ans=input(str(numberOne) +" - " +str(numberTwo)+" = __" + "\nAnswer: ")
- if (str(ans)=='e' or str(ans)=='E'):
- print("Thanks you for using Math Challenge program")
- print("Number of rights: {0}".format(rights))
- print("Number of wrongs: {0}".format(wrongs))
- quit()
- else:
- ans_int=int(ans)
- ans1= (numberOne - numberTwo)
- while (ans!=e):
- if (ans_int != ans1):
- print ("Wrong")
- wrongs=wrongs+1
- else:
- print("Correct")
- right=rights+1
- elif(question==2):
- numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
- ans=input(str(numberOne) + " - __ = " + str(numberTwo)+ "\nAnswer: ")
- if (str(ans)=='e' or str(ans)=='E'):
- print("Thanks you for using Math Challenge program")
- quit()
- else:
- ans_int=int(ans)
- ans1=(numberOne - numberTwo)
- while (ans!=e):
- if (ans_int != ans1):
- print ("Wrong")
- wrongs=wrongs+1
- else:
- print("Correct")
- right=rights+1
- elif(question==3):
- numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
- ans=input("__ - "+ str(numberOne) + " = "+ str(numberTwo)+ "\nAnswer: ")
- if (str(ans)=='e' or str(ans)=='E'):
- print("Thanks you for using Math Challenge program")
- quit()
- else:
- ans_int=int(ans)
- ans1=(numberTwo + numberOne)
- if (ans_int != ans1):
- print ("Wrong")
- wrongs=wrongs+1
- else:
- print("Correct")
- right=rights+1
- return ans
- def addition():
- global ans
- rights = 0
- wrongs = 0
- question=random.randint(1,3)
- if(question==1):
- numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
- ans=input(str(numberOne) +" + " +str(numberTwo)+" = __" + "\nAnswer: ")
- if (str(ans)=='e' or str(ans)=='E'):
- print("Thanks you for using Math Challenge program")
- quit()
- else:
- ans_int=int(ans)
- ans1= (numberOne + numberTwo)
- if (ans_int != ans1):
- print ("Wrong")
- wrongs=wrongs+1
- else:
- print("Correct")
- right=rights+1
- if(question==2):
- numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
- ans=input(str(numberOne) + " + __ = " + str(numberTwo)+ "\nAnswer: ")
- if (str(ans)=='e' or str(ans)=='E'):
- print("Thanks you for using Math Challenge program")
- quit()
- else:
- ans_int=int(ans)
- ans1= (numberTwo - numberOne)
- if (ans_int != ans1):
- print ("Wrong")
- wrongs=wrongs+1
- else:
- print("Correct")
- right=rights+1
- if(question==3):
- numberOne, numberTwo = random.randint(0,100), random.randint(0,100)
- ans=input("__ + "+ str(numberOne) + " = "+ str(numberTwo)+ "\nAnswer: ")
- if (str(ans)=='e' or str(ans)=='E'):
- print("Thanks you for using Math Challenge program")
- quit()
- else:
- ans_int=int(ans)
- ans1= (numberTwo - numberOne)
- if (ans_int != ans1):
- print ("Wrong")
- wrongs=wrongs+1
- else:
- print("Correct")
- right=rights+1
- return ans
- print(ans)
- type_of_question= random.randint(1,2)
- if(type_of_question==1):
- print(subtraction())
- else:
- print(addition())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement