This repository was archived by the owner on Jul 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultipleChoiceExample.py
More file actions
61 lines (49 loc) · 1.75 KB
/
multipleChoiceExample.py
File metadata and controls
61 lines (49 loc) · 1.75 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
50
51
52
53
54
55
56
57
58
59
60
61
# Define your questions and answers
questions = [
{
"question": "What is the capital of France?",
"options": ["a) Madrid", "b) Paris", "c) Berlin", "d) London"],
"answer": "b"
},
{
"question": "What is the largest planet in our solar system?",
"options": ["a) Jupiter", "b) Saturn", "c) Uranus", "d) Neptune"],
"answer": "a"
},
{
"question": "What is the currency of Japan?",
"options": ["a) Yen", "b) Euro", "c) Dollar", "d) Pound"],
"answer": "a"
}
]
# Initialize variables for the current question and answer
current_question = 0
current_answer = ""
# Print the first question and options
def print_question(question, options):
print(question)
for option in options:
print(option)
print_question(questions[current_question]["question"], questions[current_question]["options"])
# Loop until all questions are answered
while current_question < len(questions):
# Get user input
user_input = input("Enter your answer (a, b, c, or d) or press 'q' to quit: ")
# Check for quit command
if user_input == "q":
break
# Check for valid input
if user_input not in ["a", "b", "c", "d"]:
print("Invalid input. Please enter a, b, c, or d.")
continue
# Check the answer
current_answer = user_input
if current_answer == questions[current_question]["answer"]:
print("Correct!")
else:
print("Incorrect. The correct answer is", questions[current_question]["answer"])
# Move to the next question
current_question += 1
if current_question < len(questions):
print_question(questions[current_question]["question"], questions[current_question]["options"])
print("Thanks for playing!")