Lesson 6: Multiplication timed test

posted Nov 9, 2017, 7:49 AM by Attila Lengyel   [ updated Nov 9, 2017, 7:58 AM ]
import random
import time

correctanswer = 0
totalanswer = 0

start = time.time()
for x in range(0,10):
  totalanswer += 1
  a = random.randint(0,12)
  b = random.randint(0,12)
 
  print("What is ",a,"by",b,"is equal to?:")
  answer = input()
 
  if a * b == int(answer):
    print("Correct!!!")
    correctanswer += 1
  else:
    print("You missed it!!!")
   
print("Your score is", (correctanswer / totalanswer)*100)
end = time.time()
print("It took you", end - start, "seconds")



Comments