Quiz program using a function, a loop and a score
Calls a function that returns True for a right answer, then adds 1 to score when it does. Put this in a loop to ask every question and total the quiz score.
Understanding Quiz program using a function, a loop and a score in ACARA Digital Technologies Years 7–8
What it does: The function returns True for a right answer, so the if runs score += 1 only when the answer was correct. += adds to the variable. == only compares values, so score never changes. If score = 0 is inside the loop, the score resets to 0 on every question. == compares two values and gives True or False. A single = is assignment and causes a SyntaxError. Parameters let you pass in a different question and answer each time you call the function. Without the f before the quote, Python prints the text {score} instead of the number. The == comparison makes a True or False value. return sends that value back so an if statement can use it.
Common mistakes: The input() call is missing its closing bracket. It should be input(q + ' ') so the question is shown and the student's answer is stored in guess. A function definition must end with a colon. The first line should be def ask(q, a): so Python knows the indented lines are the function body.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 522–560) and word search (Modules 522–580).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
if ask(q, a): score += 1Fill in the Blanks
Spot the Error
Student with a class code? Join your class →