Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def display():
- print("Welcome to my awesome Math game")
- print("What is...")
- def getAnswer():
- x = randint(1,10)
- y = randint(1,10)
- op = ['+', '-', '*']
- op_int = randint(0,2)
- print(x, op[op_int], y, '=')
- ans = 0
- if op_int == 0:
- ans = x + y
- elif op_int == 1:
- ans = x - y
- else:
- ans = x * y
- return ans
- def getUserInput():
- user_ans = input("The answer is: ")
- user_ans = int(user_ans)
- return user_ans
- def getResult(computer_answer, user_answer):
- if computer_answer == user_answer:
- print("You are correct!")
- return 1
- else:
- print("You are wrong.The answer is", computer_answer,".")
- return 0
- score = 0
- repeat = True
- display()
- while repeat == True:
- ca = getAnswer()
- #print(ca)
- ua = getUserInput()
- #print(ua)
- x = getResult(ca,ua)
- print()
- score = score + x
- print('Score:', score)
- print()
- r = input("Wanna go again?(y/n)")
- if r == 'n':
- repeat = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement