Number guessing game with a loop, decisions and a counter
The loop at the heart of a guessing game. It keeps asking until the guess matches the random secret number. If/elif/else gives hints and a counter adds 1 each turn.
Understanding Number guessing game with a loop, decisions and a counter in ACARA Digital Technologies Years 7–8
What it does: This line runs once every time round the loop, so guesses goes up by 1 for every guess the player makes. The comparison guess > secret is True when the guess is too big, so the program prints a hint to guess lower. random.randint(1, 100) picks a whole number from 1 to 100. You also need import random at the top of the program. The loop must run while the guess is NOT equal to the secret. With == the loop would stop straight away unless the first guess was right. A single = stores a new value in the variable. == only compares two values, so the counter would never change.
Common mistakes: random is the module, not a function. The function that picks a whole number in a range is random.randint(1, 10). Python uses the import keyword, not include. It should be import random, otherwise random.randint will not work.
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
while guess != secret:Fill in the Blanks
Spot the Error
Student with a class code? Join your class →