Advertisement
ADevingFre

Untitled

Oct 11th, 2022
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. from random import randint, choice
  2.  
  3. operators = "+-*/"
  4. def test():
  5. right = 0
  6. total = 0
  7. while True:
  8. op_choice = choice(operators)
  9. a = randint(-20, 20)
  10. b = randint(-20, 20)
  11. if op_choice == "/":
  12. if not b:
  13. continue
  14. if a % b:
  15. continue
  16. equation = f"{a} {op_choice} {b}"
  17. result = str(round(eval(equation)))
  18. u_inp = input(f"[{right}/{total}] What is {equation}? ")
  19. if result == u_inp:
  20. print("Correct!")
  21. right += 1
  22. else:
  23. print(f"Wrong, it was {result}")
  24. total += 1
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. if __name__ == "__main__":
  32. test()
  33.  
  34.  
  35. # v0.0.1
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement