Skip to content

Commit 40fe9a1

Browse files
authored
Create interactive_quiz.py
1 parent 0daac92 commit 40fe9a1

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Day 12: Interactive Quiz Game - Project Day!
2+
3+
import random
4+
5+
# Use a list to store our questions and answers
6+
# Each item in the list is another list containing the question, options, and correct answer
7+
quiz_questions = [
8+
["What is the capital of France?", ["A) London", "B) Berlin", "C) Paris", "D) Rome"], "C"],
9+
["What is 7 times 8?", ["A) 49", "B) 56", "C) 64", "D) 72"], "B"],
10+
["What is the main color of the sky?", ["A) Green", "B) Blue", "C) Red", "D) Yellow"], "B"],
11+
["Which module is used for random numbers?", ["A) math", "B) time", "C) random", "D) sys"], "C"],
12+
["What keyword defines a function?", ["A) function", "B) func", "C) def", "D) define"], "C"]
13+
]
14+
15+
def run_quiz(questions):
16+
"""
17+
Runs the quiz game with a list of questions.
18+
"""
19+
score = 0
20+
# Optional: shuffle the questions for a new experience each time
21+
random.shuffle(questions)
22+
23+
for question_data in questions:
24+
question = question_data[0]
25+
options = question_data[1]
26+
correct_answer = question_data[2]
27+
28+
print(f"\nQuestion: {question}")
29+
for option in options:
30+
print(option)
31+
32+
user_answer = input("Your answer (A, B, C, or D): ").upper()
33+
if user_answer == correct_answer:
34+
print("Correct!")
35+
score += 1
36+
else:
37+
print(f"Incorrect. The correct answer was {correct_answer}.")
38+
39+
print(f"\nQuiz complete! You got {score} out of {len(questions)} correct.")
40+
41+
# Run the quiz when the script is executed
42+
run_quiz(quiz_questions)

0 commit comments

Comments
 (0)