← QCE Digital Solutions Unit 2

A menu loop that controls user interaction

A menu loop repeats: show the menu, read a choice, call that option's function, and stop only when the user picks quit. Other input gets an invalid choice message.

Understanding A menu loop that controls user interaction in QCE Digital Solutions Unit 2

What it does: The loop reads a choice and an if statement calls the function for that option, for example view_students() when the choice is 1. The loop must keep running while the choice is NOT q. Using == would skip the loop (or stop it) as soon as the user picks anything other than q. The user needs to see the options before choosing. The menu is shown first, then the choice is read, then the matching function is called. Invalid input should not crash or end the program. The else branch prints an invalid choice message and the loop repeats.

Common mistakes: The loop must keep running until the user picks quit, so the condition should be != "q". With == "q" the loop never starts because choice begins as an empty string. A function is only called when it has brackets. Without them the menu is never shown. It should be show_menu().

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

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which loop header keeps a menu running until the user types q to quit?
while choice != "q":while choice == "q":
Matches
while choice != "q": show_menu() if choice == "1": view_students()
↓
The choice is never read inside the loop. choice never changes, so the loop never ends and the user cannot quit. Add choice = input(...) after show_menu().
Applying
Meanings
Term
while choice != "q":
Meaning
A menu loop repeats: show the menu, read a choice, call that option's function, and stop only when the user picks quit. Other input gets an invalid choice message.
Practice
def view_students():
Testing
Gaps
choice != "q":
Check Answer
Spots
1choice = ""
2while choice == "q":

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

The 'Gazelle' badge — Tuple Sprinter, 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 header keeps a menu running until the user types q to quit?
A. while choice != "q": ✓
B. while choice == "q":
The loop must keep running while the choice is NOT q. Using == would skip the loop (or stop it) as soon as the user picks anything other than q.
2. What is the correct order of steps inside one pass of a menu loop?
A. Read a choice, call the function, then show the menu
B. Show the menu, read a choice, call that option's function ✓
The user needs to see the options before choosing. The menu is shown first, then the choice is read, then the matching function is called.
3. A user types "x", which is not a menu option. What should the menu loop do?
A. Print an invalid choice message and show the menu again ✓
B. End the program straight away
Invalid input should not crash or end the program. The else branch prints an invalid choice message and the loop repeats.
4. Which line belongs in the loop to handle the quit option?
A. elif choice == "q": print("Goodbye") ✓
B. elif choice == "q": choice = "a"
The quit option should tell the user the program is ending. Setting choice to something else would keep the loop running, so the user could never quit.
5. Why must the choice be read INSIDE the while loop?
A. So the menu is only shown once
B. So the user can pick a new option on every repeat ✓
If input() sits before the loop, choice never changes and the loop either never ends or repeats the same option forever. Reading it inside lets the user choose again each time.

Match the Pairs

while choice != "q": → Keeps the menu repeating until the user types q to quit
else: print("Invalid choice") → Shows an invalid choice message when the input matches no menu option, then the menu appears again
Each valid menu option calls its own function inside the loop → if choice == "1": view_students()
The menu must read a new choice on every pass so the user can quit → while choice != "q": choice = input("Choice: ")
while choice != "q": show_menu() if choice == "1": view_students() → The choice is never read inside the loop. choice never changes, so the loop never ends and the user cannot quit. Add choice = input(...) after show_menu().
while choice != "q": choice = input("Choice: ") if choice == "1": view_students() elif choice == "2": add_student() → There is no else branch, so an invalid choice is ignored silently. Add else: print("Invalid choice") so the user knows to try again.

Key Term

while choice != "q":
A menu loop repeats: show the menu, read a choice, call that option's function, and stop only when the user picks quit. Other input gets an invalid choice message.

Fill in the Blanks

1. choice = "" while choice != "q": print_menu()
Hint: Type the keyword that keeps repeating the menu while the quit choice has not been entered.
2. choice = input("Choice: ") while choice != "q":
Hint: Type the comparison operator meaning 'is not equal to', so the loop runs until the user quits.
3. elif choice == "2": show_students()
Hint: Type the keyword that checks the next menu option only if the earlier option did not match.
4. else: print("Invalid choice, try again")
Hint: Type the keyword for the branch that catches every choice not matched above, to show the invalid choice message.
5. choice = input("Enter choice: ") run_option(choice)
Hint: Type the built-in function that reads the user's menu choice from the keyboard.

Spot the Error

Question 1
A choice = ""
B while choice == "q":
C choice = input("Option: ")
D if choice == "1":
E view_items()
Line B — The loop must keep running until the user picks quit, so the condition should be != "q". With == "q" the loop never starts because choice begins as an empty string.
Question 2
A choice = ""
B while choice != "q":
C show_menu
D choice = input("> ")
Line C — A function is only called when it has brackets. Without them the menu is never shown. It should be show_menu().
Question 3
A choice = ""
B while choice != "q":
C choice = int(input("> "))
D if choice == "1":
E add_item()
Line C — int() would crash when the user types q to quit, and a number would never equal the string "q". Menu choices should stay as strings: choice = input("> ").
Question 4
A def main:
B choice = ""
C while choice != "q":
D choice = input("> ")
Line A — A function definition needs brackets after its name. It should be def main():.
Question 5
A choice = ""
B while choice != "q":
C choice = input("> ")
D if choice == 1:
E view_items()
F elif choice == "2":
Line D — input() returns text, so choice is the string "1". Comparing it to the number 1 is never true and the option's function would never run. It should be if choice == "1":.

Student with a class code? Join your class →