← QCE Digital Solutions Unit 3

A menu loop to control user interactions

Starts a menu loop that repeats forever: show options, read a choice, call the matching function with if/elif, reject invalid input, and break when the user picks quit.

Understanding A menu loop to control user interactions in QCE Digital Solutions Unit 3

What it does: The else runs only when no if or elif matched, so the user sees an error message and the loop shows the menu again. The user must see the options and enter a choice before the program can decide which function to call. Use == to compare values. A single = is assignment and causes a syntax error in a condition. An if/elif chain checks the options in order and stops at the first match. A final else handles every other choice. Handling an invalid choice means the loop continues. The user gets feedback and another chance to choose. while True repeats forever unless something such as break stops it. Every menu needs a quit option.

Common mistakes: A single = assigns a value and is not allowed in an if condition. Use == to compare the user's choice with "1". The input() call is missing its closing bracket, which causes a SyntaxError. It should end with ) like this: input("Choice: ").

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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 251–337) and word search (Modules 194–337).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which loop keeps a menu showing until the user chooses to quit?
for i in range(1): ... then the program endswhile True: ... break when the choice is 'Q'
Matches
while True: choice = input("Choice: ") if choice == "3": print("Bye")
↓
The quit branch never uses break, so the loop never ends and the menu keeps appearing after the user chooses quit.
Applying
Meanings
Term
while True:
Meaning
Starts a menu loop that repeats forever: show options, read a choice, call the matching function with if/elif, reject invalid input, and break when the user picks quit.
Practice
def show_scores():
Testing
Gaps
True:
Check Answer
Spots
2 choice = input("Choice: ")
3 if choice = "1":

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Blobfish' badge — Pressure Handler, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which loop keeps a menu showing until the user chooses to quit?
A. while True: ... break when the choice is 'Q' ✓
B. for i in range(1): ... then the program ends
A while True loop repeats the menu again and again. The break statement runs only when the user picks quit.
2. Which order is correct inside a menu loop?
A. Show the menu, read the choice, call the matching function ✓
B. Call the matching function, read the choice, show the menu
The user must see the options and enter a choice before the program can decide which function to call.
3. Which code dispatches the choice to the right function?
A. if choice = '1': add_item() elif choice = '2': view_items()
B. if choice == '1': add_item() elif choice == '2': view_items() ✓
Use == to compare values. A single = is assignment and causes a syntax error in a condition.
4. Why use elif rather than a separate if for each menu option?
A. elif makes the menu loop run faster than if
B. Only one matching branch runs, and the else can catch anything left over ✓
An if/elif chain checks the options in order and stops at the first match. A final else handles every other choice.
5. The user types 'x', which is not a menu option. What should the menu loop do?
A. Show an error message in an else branch and display the menu again ✓
B. End the program without a message
Handling an invalid choice means the loop continues. The user gets feedback and another chance to choose.

Match the Pairs

while True: → Starts a menu loop that keeps showing the menu until the program reaches a break
elif choice == "2": → Checks whether the user picked option 2 and, if so, runs that option's function
An invalid choice is handled by an else branch that shows an error and lets the loop repeat → else: print("Invalid choice")
The quit option ends the menu loop and returns control to the rest of the program → elif choice == "3": break
while True: choice = input("Choice: ") if choice == "3": print("Bye") → The quit branch never uses break, so the loop never ends and the menu keeps appearing after the user chooses quit.
while True: choice = input("Choice: ") if choice = "1": add_item() → A single = assigns a value instead of comparing. The condition needs == to check the user's choice.

Key Term

while True:
Starts a menu loop that repeats forever: show options, read a choice, call the matching function with if/elif, reject invalid input, and break when the user picks quit.

Fill in the Blanks

1. while True: choice = input("Choice: ") if choice == "1":
Hint: Type the keyword that starts a loop which repeats while its condition stays true.
2. if choice == "1": addItem() elif choice == "2":
Hint: Type the keyword that adds another choice to the same if chain.
3. elif choice == "q": break else:
Hint: Type the keyword for the branch that catches any choice not matched above, so an invalid choice is rejected.
4. elif choice == "3": break else:
Hint: Type the keyword that exits the menu loop straight away when the user picks quit.
5. while True: showMenu() choice = input("Choice: ")
Hint: Type the built-in function that reads the user's menu choice from the keyboard.

Spot the Error

Question 1
A while True:
B choice = input("Choice: ")
C if choice = "1":
D start_game()
E elif choice == "2":
F break
Line C — A single = assigns a value and is not allowed in an if condition. Use == to compare the user's choice with "1".
Question 2
A while True:
B print("1 Play 2 Quit")
C choice = input("Choice: "
D if choice == "2":
E break
F play()
Line C — The input() call is missing its closing bracket, which causes a SyntaxError. It should end with ) like this: input("Choice: ").
Question 3
A while False:
B choice = input("Choice: ")
C if choice == "Q":
D break
E print("Invalid choice")
Line A — A menu loop must start with while True: so it keeps running until the user chooses to quit. while False: never runs the menu at all.
Question 4
A while True:
B choice == input("> ")
C if choice == "Q":
D break
E else:
F print("Invalid choice")
Line B — == compares values and does not store anything, so choice is never created. Use a single = to assign the user's input to choice.
Question 5
A while True:
B choice = input("> ")
C if choice == 1:
D view_scores()
E elif choice == "Q":
F break
Line C — input() always returns a string, so choice is "1" and never equals the number 1. The menu option would never be matched. Compare with the string "1".

Student with a class code? Join your class →