-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmultiplication_quiz.py
More file actions
49 lines (43 loc) · 1 KB
/
multiplication_quiz.py
File metadata and controls
49 lines (43 loc) · 1 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Project: Multiplication Quiz Game
Author:Shiva Prasad K Thamban
Description:
Create a quiz program that tests the user's multiplication skills.
Requirements:
1. Generate two random numbers.
2. Ask the user to calculate their multiplication.
3. Check if the answer is correct.
4. Keep track of the score.
5. Continue asking questions until the user types 'exit'.
Sample Output:
Question: 6 x 7 = ?
Your answer: 42
Correct!
Question: 5 x 9 = ?
Your answer: 40
Wrong! The correct answer is 45
Type 'exit' to stop the quiz.
Final Score: 1
"""
import random
def numgen():
a=random.randint(1,50)
b=random.randint(1,50)
return a,b
score=0
count=0
choice=""
while True:
a,b=numgen()
print("Question ",count+1,": ",a,"x",b," = ?")
choice=input("Your answer: ")
if choice=="exit":
print("\n")
break
if int(choice)==a*b:
print("Correct!\n")
score+=1
else:
print("Wrong! The correct answer is ",a*b,"\n")
count+=1
print("Final score= ",score,"\n")