Pseudocode for user interaction: prompts and menus

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Pseudocode for user interaction: prompts and menus

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which order correctly asks the user for their age in pseudocode?
A input age then print "Enter your age:"
B print "Enter your age:" then input age
2. What is the purpose of the print line before an input line?
A It tells the user what to enter
B It stores the user's answer in a variable
3. A menu loop needs to keep showing the options until the user is finished. Which structure fits best?
A A loop that repeats until the exit option is chosen
B A single if statement that runs once
4. Which choice handling selects the matching action for a menu option?
A if choice = 1 then ... else if choice = 2 then ...
B if choice = 1 then ... if choice = 2 then ... on the same variable inside a for loop of 1 to 1
5. Which menu loop will stop when the user picks the exit option 3?
A repeat ... until choice = 0 (when the exit option is 3)
B repeat ... until choice = 3

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1print "Enter your age:" input age AThe input comes before the print prompt, so the user is asked for a choice after the program has already tried to read it. The prompt must be printed first.
2while choice != 3 BShows a prompt to the user, then reads their reply into the variable age.
3A menu uses if / else if to run the action that matches the user's choice. Cif choice = 1 then print "Adding item" else if choice = 2 then print "Showing list" end if
4A menu loop prints the options, reads a choice and repeats until the exit option is picked. Drepeat print "1 Add 2 View 3 Exit" input choice until choice = 3
5input choice print "Pick an option (1-3):" EThe exit condition uses 3, but the menu only offers options 1 and 2, so the user can never exit and the loop runs forever. The condition should be choice = 2.
6repeat print "1 Play 2 Quit" input choice until choice = 3 FKeeps the menu repeating until the user picks option 3, the exit option.

Definitions

menu loop

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
print "Enter your name:" _____ name
2.
_____ "Enter a number from 1 to 3:" input num
3.
while choice ≠ _ print "1 Play 2 Help 3 Exit" input choice
4.
if choice = 1 then print "Starting game" _______ choice = 2 then
5.
print "Choose 1, 2 or 3:" input ______ if choice = 1 then

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A print "Enter your age:"
B input age
C if age >= 18
D print "Adult"
E end if
Question 2
A choice <- 0
B print "Enter choice (1-3):"
C read choice
D print "You chose " + choice
Question 3
A print "Enter your name:"
B input <- name
C print "Hi " + name
Question 4
A choice <- 1
B while choice = 0
C print "1 Add 0 Quit"
D input choice
E end while
Question 5
A input choice
B if choice = 1 then
C print "Playing"
D else choice = 2 then
E print "Help"
F end if

Answer Key

Pseudocode for user interaction: prompts and menus
Section A: Quick Questions
Q1
B — print "Enter your age:" then input age
Q2
A — It tells the user what to enter
Q3
A — A loop that repeats until the exit option is chosen
Q4
A — if choice = 1 then ... else if choice = 2 then ...
Q5
B — repeat ... until choice = 3
Section B: Match the Pairs
Q1
print "Enter your age:" input age → Shows a prompt to the user, then reads their reply into the variable age.
Q2
while choice != 3 → Keeps the menu repeating until the user picks option 3, the exit option.
Q3
A menu uses if / else if to run the action that matches the user's choice. → if choice = 1 then print "Adding item" else if choice = 2 then print "Showing list" end if
Q4
A menu loop prints the options, reads a choice and repeats until the exit option is picked. → repeat print "1 Add 2 View 3 Exit" input choice until choice = 3
Q5
input choice print "Pick an option (1-3):" → The input comes before the print prompt, so the user is asked for a choice after the program has already tried to read it. The prompt must be printed first.
Q6
repeat print "1 Play 2 Quit" input choice until choice = 3 → The exit condition uses 3, but the menu only offers options 1 and 2, so the user can never exit and the loop runs forever. The condition should be choice = 2.
Section C: Definitions
Q1
menu loop — A loop that prints the options, uses a print prompt then input to read a choice, runs the matching action with if / else if, and repeats until the user picks the exit option.
Section D: Fill in the Blanks
Q1
print "Enter your name:" input name
Q2
print "Enter a number from 1 to 3:" input num
Q3
while choice ≠ 3 print "1 Play 2 Help 3 Exit" input choice
Q4
if choice = 1 then print "Starting game" else if choice = 2 then
Q5
print "Choose 1, 2 or 3:" input choice if choice = 1 then
Section E: Spot the Error
Q1
C — An if statement needs the keyword then after its condition. The line should be: if age >= 18 then
Q2
C — Pseudocode uses the keyword input to read a value from the user, not read. The line should be: input choice
Q3
B — input is followed directly by the variable that stores the typed value. No assignment arrow is used. The line should be: input name
Q4
B — The menu must keep looping until the user picks the exit option, so the condition should be choice != 0. With = the loop would stop straight away, or never run properly.
Q5
D — A chained selection needs the keywords else if before the next condition. The line should be: else if choice = 2 then