GCSE Python · Lesson 9 of 9

GCSE mini-project: quiz and scoreboard

OCR J277 programming / AQA 8525 programming

Combine selection, lists, functions, validation and testing into one quiz.

← All GCSE Python lessons

Combining programming skills

A small quiz with a scoreboard combines lists, selection, loops, functions and validation. Start with a minimum working version, then introduce one new feature at a time. Use a clear testing checklist before calling it complete.

Watch out: Avoid adding extra features before the core quiz works reliably. A smaller, tested program is better than a complex unfinished one.

1 · Learn and predict

Read this worked example. Predict its output, run it in Python 3, and explain how variables change.

questions = [('2 + 2?', '4'), ('Binary of 2?', '10')]
score = 0
for question, expected in questions:
    # Replace the fixed response with input() later.
    response = expected
    if response == expected:
        score += 1
print('Score:', score, 'out of', len(questions))

2 · Build independently

Combine selection, lists, functions, validation and testing into one quiz. Work from the starter code before comparing with the solution.

Download starter + solution ZIP ↓

For a stretch challenge: add meaningful test data, handle an edge case and explain one design decision.

Reveal reference solution
def run_quiz(questions, ask=input):
    score = 0
    for question, expected in questions:
        response = ask(question + ' ').strip().lower()
        if response == expected.lower():
            print('Correct!')
            score += 1
        else:
            print('Answer:', expected)
    return score

QUESTIONS = [('2 + 2?', '4'), ('Binary of 2?', '10'),
             ('Keyword for a function?', 'def')]

if __name__ == '__main__':
    result = run_quiz(QUESTIONS)
    print('Score:', result, '/', len(QUESTIONS))

The reference is one possible approach. Test your own program before comparing.

3 · Debug and explain

Question: How would you test the scoreboard without repeatedly typing answers?

Show explanation

Pass a controlled replacement for the input function, or test a separate scoring function.

4 · Check your understanding

Why store questions in a list?

5 · Reflect

Explain one test you used, one problem you solved and one improvement you would make.

This records completion only in this browser and does not certify mastery.

Want extra practice? Try interactive Python tracing and debugging questions →