Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- #initialise variables
- with open('highscore.txt','r') as f:
- highscore = int(f.read())
- print('The current highscore is {}'.format(highscore))
- cnt = True
- question = 0
- print('Welcome to the maths quiz')
- score = 0
- while cnt:
- question += 1
- a = randint(1,3)
- b = randint(1,3)
- c = randint(1,3)
- answer = a * b * c
- response = int(input('{}. What is the product of {} * {} * {}?'.format(question,a,b,c)))
- if answer == response:
- score += 1
- print('Correct, Scrore is {}'.format(score))
- else:
- print('Incorrect, Correct answer is {}'.format(answer))
- cnt = False
- if score > highscore:
- highscore = score
- with open('highscore.txt','w') as f:
- print('A new Highscore!')
- f.write(str(highscore))
- print('Highscore is {}'.format(highscore))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement