-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuiz.py
60 lines (56 loc) · 1.61 KB
/
Quiz.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
questions = []
score = 0
def attempt_quiz():
global score
print("Welcome to the Quiz!")
print("Answer the following questions:")
print("--------------------------------")
for question in questions:
print(question['question'])
print("Options:")
for i, option in enumerate(question['options'], start=1):
print(f"{i}. {option}")
answer = input("Your answer (enter the option number): ")
if answer == question['answer']:
print("Correct!")
score += 1
else:
print("Incorrect!")
break
print("--------------------------------")
print("Quiz complete!")
print(f"Your score: {score}/{len(questions)}")
print()
def add_question():
question_text = input("Enter the question: ")
options = []
for i in range(4):
option = input(f"Enter option {i+1}: ")
options.append(option)
answer = input("Enter the correct option number: ")
question = {
'question': question_text,
'options': options,
'answer': answer
}
questions.append(question)
print("Question added successfully!")
print()
while True:
print("Menu:")
print("1. Attempt Quiz")
print("2. Add Question")
print("3. Quit")
choice = input("Enter your choice (1-3): ")
print()
if choice == '1':
score = 0
attempt_quiz()
elif choice == '2':
add_question()
elif choice == '3':
print("Thank you for using the Quiz program. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
print()