-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmart_quiz_generator.py
More file actions
39 lines (29 loc) · 975 Bytes
/
Copy pathsmart_quiz_generator.py
File metadata and controls
39 lines (29 loc) · 975 Bytes
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
import random
def generate_math_question():
a = random.randint(1, 50)
b = random.randint(1, 50)
operator = random.choice(['+', '-', '*'])
question = f"What is {a} {operator} {b}?"
if operator == '+':
answer = a + b
elif operator == '-':
answer = a - b
else:
answer = a * b
return question, answer
def main():
print("Welcome to Smart Quiz Generator 1.0")
num_questions = int(input("How many questions would you like? "))
score = 0
for i in range(num_questions):
question, answer = generate_math_question()
print(f"\nQuestion {i + 1}: {question}")
user_answer = int(input("Your answer: "))
if user_answer == answer:
print("Correct!")
score += 1
else:
print(f"Wrong. The correct answer was {answer}")
print(f"\nYou answered {score} out of {num_questions} correctly. Well done!")
if __name__ == "__main__":
main()