Advertisement
ssoni

mathtest.py

Dec 5th, 2023
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. import random
  2.  
  3. def main():
  4.     numWrong = 0
  5.     numCorrect = 0
  6.     while (numWrong < 3):
  7.         a = random.randrange(1,10)
  8.         b = random.randrange(1,10)
  9.         op = random.randrange(1,5)
  10.  
  11.         match op:
  12.             case 1:
  13.                 solution = a+b
  14.                 oper = '+'
  15.             case 2:
  16.                 solution = a-b
  17.                 oper = '-'
  18.             case 3:
  19.                 solution = a*b
  20.                 oper = '*'
  21.             case 4:
  22.                 solution = round(a/b,1)
  23.                 oper = '/'
  24.  
  25.         ans = float(input(f'{a} {oper} {b} = '))
  26.         if ans == solution:
  27.             numCorrect = numCorrect + 1
  28.             print('Correct')
  29.         else:
  30.             print('Incorrect')
  31.             numWrong = numWrong + 1
  32.  
  33.     print(f'You got {numCorrect} correct')
  34. main()
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement