──────────────────────────────────────

39. Pocket Quiz Capstone · Score a Complete Round

Add the result from each question and verify a partly correct round.

Lesson files · lessons/foundations-capstone/test-full-round

Before you start
- Use a running total across a loop.
- Use a for loop to visit the items in a list.
- Check a reply after trimming and lowercasing it.

By the end
- Use one counter to collect points across the entire quiz.
- Use the length of the answer list to show the maximum score.
- Test a run with both correct and wrong answers.

Where you can use it
Give a practice quiz one score for the whole round. Try a run with some correct replies so you can check that the score adds up.

Loop through the answer keys in order. Each time, read a fresh reply and use the same cleaning rule as is_correct. Start the score at 0 before the loop and add one when a reply matches.

Predict the score for one correct and one wrong reply. A mixed run checks that your program can both award a point and leave the score alone. After the loop, len(answers) gives the number of possible points.

Predict
Why keep score outside the loop?
- It must remember points from all questions.
- It must restart on each question.

Worked example (example.py)

answers = ["mars", "4"]
score = 0
for expected in answers:
    if input().strip().lower() == expected:
        score += 1
print(f"Score: {score}/{len(answers)}")


Example input
mars
5

Example result
Score: 1/2

Add cow as the third answer key. Print the final score in the same format. Predict the score for a mix of correct and wrong replies, then run it.

Starter program (starter.py)

answers = ["mars", "4"]
score = 0
for expected in answers:
    if input().strip().lower() == expected:
        score += 1
print(f"Score: {score}/{len(answers)}")


Starter input
mars
5

Hint
Add cow to the list. The same loop and denominator should handle the extra round.

Case 1. Try the sample
Input
Mars
5
Cow
Expected output
Score: 2/3

Case 2. All wrong
Input
venus
7
koala
Expected output
Score: 0/3

Stretch
Write a prediction for all three correct answers, then test it.

Reflect
What does the mix of correct and wrong answers tell you about your program?

Check your prediction
It must remember points from all questions. The total should carry over to the next question.
