Automate the Boring Stuff with Python (Chapter 8): Write Your Own Multiplication Quiz
0
Author: Vasyl MakoviychukPY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import random, time
print('Multiplication Quiz\n')
def first_question():
time.perf_counter()
first_number = random.randint(0, 9)
last_number = random.randint(0, 9)
result = first_number * last_number
answer = int(input('Type the result of '+str(first_number)+' x '+str(last_number)+': '))
if answer == result and int(time.perf_counter()) < 8:
print('Correct!\n')
time.sleep(1)
elif int(time.perf_counter()) >= 8:
print('Sorry, you have only 8 sec.\n')
else:
for t in range(2):
next_answer = int(input('\nTry again '+str(first_number)+' x '+str(last_number)+': '))
if next_answer == result:
print('Correct!\n')
time.sleep(1)
def second_question():
new_limit = time.perf_counter() + 8
first_number = random.randint(0, 9)
last_number = random.randint(0, 9)
result = first_number * last_number
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run