Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def main():
- numWrong = 0
- numCorrect = 0
- while (numWrong < 3):
- a = random.randrange(1,10)
- b = random.randrange(1,10)
- op = random.randrange(1,5)
- match op:
- case 1:
- solution = a+b
- oper = '+'
- case 2:
- solution = a-b
- oper = '-'
- case 3:
- solution = a*b
- oper = '*'
- case 4:
- solution = round(a/b,1)
- oper = '/'
- ans = float(input(f'{a} {oper} {b} = '))
- if ans == solution:
- numCorrect = numCorrect + 1
- print('Correct')
- else:
- print('Incorrect')
- numWrong = numWrong + 1
- print(f'You got {numCorrect} correct')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement