Kingsamofgames

Maths Test code

Aug 3rd, 2022 (edited)
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import time
  2. import random
  3.  
  4. total_time = 0
  5. score = 0
  6. operators = ["+", "-", "*"]
  7. for i in range(10):
  8.     num1 = random.randint(10, 99)
  9.     num2 = random.randint(10, 99)
  10.     operator = random.choice(operators)
  11.     if operator == "+":
  12.         answer = num1 + num2
  13.     elif operator == "-":
  14.         answer = num1 - num2
  15.     else:
  16.         answer = num1 * num2
  17.     start = time.time()
  18.     print(f"What is {num1} {operator} {num2}?")
  19.     guess = input("Please enter your answer here: ")
  20.     end = time.time() - start
  21.     guess = int(guess)
  22.     total_time += end
  23.     if guess == answer:
  24.         score += 1
  25.  
  26.  
  27. total_time = round(total_time/60, 2)
  28. rank = round(score/total_time, 2)
  29. print(f"You got {score} out of 10 in {total_time} minutes. You got {rank} points per minute")
  30.  
Advertisement
Add Comment
Please, Sign In to add comment