From Working Code to Program Design · practice
Revisit the Quiz Engine
The final Fundamentals I capstone was a working quiz engine. This smaller version starts from the same familiar pieces:
a
of question ; one response for each question;
a
that checks one answer; a function that
through the quiz and counts correct responses.
questions = [
{
"prompt": "What does len('cat') return?",
"answer": "3",
},
{
"prompt": "Which keyword starts a function?",
"answer": "def",
},
]
Each dictionary models one question. The keys establish an informal agreement: every record should provide a prompt and an answer.
Follow the call
The quiz loop can select matching positions from the two lists:
for index in range(len(question_list)):
question = question_list[index]
response = response_list[index]
It then asks check_answer for a
if check_answer(question, response):
score += 1
The design is procedural, readable, and suitable for a small program. We are not looking for an excuse to replace it. We are establishing a working baseline that later designs must genuinely improve.
Put one quiz iteration in order:
Drag the options into order, or use the arrow buttons.
Compare the response with the stored answer.
Increase the score when the result is true.
Select a question and its matching response.
Call
check_answer.
Complete the familiar function
The editor provides the data and check_answer. Complete run_quiz without changing the data model. This is a reading and reconstruction exercise, not a design rewrite.
Task
Complete run_quiz.
check_answer, and return the number of correct responses. The provided program should print Score: 2/3.