Advertisement
JAS_Software

Simple Maths Quiz

May 5th, 2021
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from random import randint
  2.  
  3. #initialise variables
  4. with open('highscore.txt','r') as f:
  5.     highscore = int(f.read())
  6.  
  7. print('The current highscore is {}'.format(highscore))
  8. cnt = True
  9. question = 0
  10.  
  11. print('Welcome to the maths quiz')
  12. score = 0
  13. while cnt:
  14.     question += 1
  15.     a = randint(1,3)
  16.     b = randint(1,3)
  17.     c = randint(1,3)
  18.     answer = a * b * c
  19.     response = int(input('{}. What is the product of {} * {} * {}?'.format(question,a,b,c)))
  20.     if answer == response:
  21.         score += 1
  22.         print('Correct, Scrore is {}'.format(score))
  23.     else:
  24.         print('Incorrect, Correct answer is {}'.format(answer))
  25.         cnt = False
  26.        
  27. if score > highscore:
  28.     highscore = score
  29.     with open('highscore.txt','w') as f:
  30.         print('A new Highscore!')
  31.         f.write(str(highscore))
  32.        
  33.  
  34. print('Highscore is {}'.format(highscore))
  35.  
  36.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement