the-honk/school/gcse/year 9/python challenges/26 - Maths quiz with results saving.py

37 lines
705 B
Python
Raw Normal View History

2021-05-28 20:38:55 +00:00
import uuid
name = input('Please input your name!')
score = 0
def question1(score):
answer = int(input('What is 5 times 5?'))
if answer == 25:
score = score + 1
question2(score)
def question2(score):
answer = int(input('What is 12 times 12?'))
if answer == 144:
score = score + 1
question3(score)
def question3(score):
answer = int(input('What is 3 cubed?'))
if answer == 27:
score = score + 1
save(score)
def save(score):
f = open('quizresult-' + str(uuid.uuid1()) + '.txt', 'x')
f.write('Name: ' + name)
f.write('\nQuiz result: ' + str(score) + '/3')
f.close()
print('Written results to file.')
question1(score)