class Question:
def __init__(self, question, choices, correct_choice):
self.question = question
self.choices = choices
self.correct_choice = correct_choice
def is_correct(self, choice):
return choice == self.correct_choice
def run_quiz(questions):
score = 0
for question in questions:
print(question.question)
for i, choice in enumerate(question.choices, start=1):
print(f"{i}. {choice}")
user_choice = int(input("Enter the number of your choice: "))
if question.is_correct(user_choice):
print("Correct!\n")
score += 1
else:
print(f"Incorrect. The correct answer was {question.correct_choice}: {question.choices[question.correct_choice - 1]}\n")
print(f"You scored {score}/{len(questions)}.")
# Define your quiz questions here
questions = [
Question("What command is used to include other functions that were previously developed?", ["Export", "Else", "Import", "IDK"], 3),
Question("What command is used to evaluate correct or incorrect response in this example?", ["And", "If", "Else", "Return"], 2),
Question("Where is Del Norte High School located?", ["Atlantic Ocean", "Escondido", "The Bronx", "Del Sur"], 4)
]
# Run the quiz
run_quiz(questions)
What command is used to include other functions that were previously developed?
1. Export
2. Else
3. Import
4. IDK
Correct!
What command is used to evaluate correct or incorrect response in this example?
1. And
2. If
3. Else
4. Return
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[4], line 35
28 questions = [
29 Question("What command is used to include other functions that were previously developed?", ["Export", "Else", "Import", "IDK"], 3),
30 Question("What command is used to evaluate correct or incorrect response in this example?", ["And", "If", "Else", "Return"], 2),
31 Question("Where is Del Norte High School located?", ["Atlantic Ocean", "Escondido", "The Bronx", "Del Sur"], 4)
32 ]
34 # Run the quiz
---> 35 run_quiz(questions)
Cell In[4], line 17, in run_quiz(questions)
15 for i, choice in enumerate(question.choices, start=1):
16 print(f"{i}. {choice}")
---> 17 user_choice = int(input("Enter the number of your choice: "))
18 if question.is_correct(user_choice):
19 print("Correct!\n")
ValueError: invalid literal for int() with base 10: ''