B. Software Development · Software Development: Problem Solving, Design, Testing and the Life CycleDesigning User-Friendly Interfaces
B2.5About 65 minutes
Learning goals- I can write clear prompts that tell the user what to enter, in what format and with what units.
- I can write helpful messages, including error messages that explain what went wrong and how to fix it.
- I can design a text menu screen and a form so that they are easy to use and hard to misuse.
- I can use input validation loops and confirmations to protect the user from mistakes.
Words to know
user interface (UI)
Everything the user sees and interacts with: prompts, messages, menus, screens, forms and buttons.
prompt
Text that asks the user for input. A good prompt says what to type, the format and the allowed range.
input validation
Checking that input is sensible (right type, in range) before using it, and asking again if it is not.
menu
A list of numbered or lettered choices the user picks from.
form
A screen that collects several related pieces of information, each with a label.
confirmation
A question that lets the user check an important action (like a payment) before it happens.
accessibility
Designing so that everyone can use the software, including people who use screen readers, people with colour blindness and people who use only a keyboard.
The user is not inside your head
You know your program expects a number from 1 to 4. The user does not. If the screen just shows ?, they have to guess. If they guess wrong and see ERROR 37, they give up.
A user-friendly interface makes the right action obvious and mistakes hard to make. The Ontario curriculum lists four parts of an interface to design: prompts, messages, screens and forms. Even a simple text program has all four.
The same rink-booking program with two different interfaces. The friendly version names the program, gives the allowed range in the prompt, explains the error, and confirms the cost before booking.Prompts
A good prompt answers the user's question "What do I type?"
- Say what to enter:
Hours to book rather than ?. - Give the format or units:
Date (YYYY-MM-DD), Distance (km). - Give the range or choices:
(1-4), Type Y or N. - End with a colon and a space, so typing does not run into the text.
Messages
Messages tell the user what is happening. Error messages are the most important:
- Say what went wrong in plain words (not codes).
- Say how to fix it.
- Be polite. Never blame or insult the user.
Sorry, you can book 1 to 4 hours. Please try again. is far better than INVALID INPUT.
Also give feedback after an action ("Booked! See you on the ice.") and confirm before anything that costs money or deletes data.
Worked exampleExample 1: Improving prompts and messages
Rewrite this unfriendly code: n = input("?") and, for bad input, print("ERROR"). The program needs the number of hours (a whole number from 1 to 4) to book the community rink at $90 per hour.
- Prompt: say what, and give the range:
input("Hours to book (1-4): "). - Validation: use a
while loop. While the number is out of range, explain and ask again. - Error message: say what is allowed and how to fix it.
- Confirmation: show the cost and ask Y/N before booking. Accept
y or Y and ignore spaces with .strip().upper(). - Feedback: tell the user what happened in both cases.
The program is below. With the inputs 6, 2, y it explains that 6 is not allowed, then confirms and books 2 hours for $180.00.
hours = int(input("Hours to book (1-4): "))
while hours < 1 or hours > 4:
print("Sorry, you can book 1 to 4 hours. Please try again.")
hours = int(input("Hours to book (1-4): "))
cost = hours * 90
answer = input(f"Book {hours} h for ${cost:.2f}? Type Y or N: ")
if answer.strip().upper() == "Y":
print("Booked! See you on the ice.")
else:
print("No booking made.")
Sample run: the user types 6 (rejected with a helpful message), then 2, then y. The program shows Book 2 h for $180.00? Type Y or N: and then Booked! See you on the ice.
Screens and menus
A screen in a text program is a group of output lines the user sees at once. Make screens easy to scan:
- A title at the top so the user knows where they are.
- Numbered choices in a menu, with a Quit option.
- Consistent layout and wording on every screen.
- Blank lines or separators between sections.
A menu program usually has a loop: show the menu, get a valid choice, do the task, and repeat until the user chooses Quit.
Worked exampleExample 2: A menu-driven program
Design a temperature helper with a menu: 1 converts °C to °F, 2 converts °F to °C, 3 quits. Invalid choices must get a friendly message.
- Use modularity:
show_menu() prints the screen; get_choice() returns a valid choice only; main() runs the loop. get_choice() uses .strip() (so " 2 " works) and keeps asking while the choice is not one of "1", "2", "3". Comparing strings avoids a crash if the user types a letter.main() uses while True: and leaves with break when the user picks 3.- Trace a run with inputs 4, 1, −10, 3: 4 is rejected; 1 then −10 gives −10 × 9 ÷ 5 + 32 = 14.0 °F; the menu shows again; 3 says goodbye.
See the program and sample run below.
def show_menu():
print("=== Temperature Helper ===")
print("1. Celsius to Fahrenheit")
print("2. Fahrenheit to Celsius")
print("3. Quit")
def get_choice():
choice = input("Choose 1, 2 or 3: ").strip()
while choice not in ("1", "2", "3"):
print(f"Sorry, '{choice}' is not an option. Please type 1, 2 or 3.")
choice = input("Choose 1, 2 or 3: ").strip()
return choice
def main():
while True:
show_menu()
choice = get_choice()
if choice == "3":
print("Goodbye! Stay warm.")
break
temp = float(input("Temperature: "))
if choice == "1":
print(f"{temp} C = {temp * 9 / 5 + 32:.1f} F")
else:
print(f"{temp} F = {(temp - 32) * 5 / 9:.1f} C")
main()
Sample run: inputs 4, 1, -10, 3. The program prints the menu, rejects 4 with Sorry, '4' is not an option. Please type 1, 2 or 3., converts with -10.0 C = 14.0 F, shows the menu again and ends with Goodbye! Stay warm. (Typing a word at the Temperature prompt would still crash it. The exceptions lesson fixes that.)
Forms
A form collects several related inputs on one screen, as in a sign-up page or a graphical (GUI) app. The same rules apply, plus a few more:
- A clear label for every field, placed next to it.
- Mark required fields (often with an asterisk,
*) and say which are optional. - Show an example or the allowed range inside or beside the field.
- Group related fields and put them in a logical order (name before address).
- The button says what it does ("Sign up", not "OK").
- Check each field and show the error next to the field that needs fixing.
Design for everyone
Accessible interfaces work for more people: don't use colour as the only signal ("fields in red are wrong" fails for people with colour blindness; add a symbol or words), use plain language, make text large enough, and make sure everything works from the keyboard alone, which also helps people who use screen readers.
Anatomy of a user-friendly form. Every design choice on the right helps the user enter the right information the first time.Just for funSome cities have "desire paths": dirt trails worn across the grass where people ignore the sidewalk and take the shortcut they actually want. Users treat software the same way. If your interface fights them, they'll find a path around it.
Hands-on activityUsability test at home
You need: a computer with Python and one or two family members as testers.
- Write (or reuse) a small program with at least two prompts, one menu and one validation loop. The temperature helper works well.
- Ask a tester to use it without any help from you. Sit beside them silently and write down every time they hesitate, ask a question or type something unexpected.
- Then ask: "What was confusing? What would you change?"
- Improve at least three prompts or messages based on what you saw. Test again with someone new if you can.
What to look for: the improved version should need no explanation. Common fixes: adding a range to a prompt, rewording an error message so it explains the fix, adding a title or Quit option, accepting both upper- and lower-case answers.
Your turn
1Improve this prompt: input("Enter: ") for a program that needs a birth year.
Example: input("Birth year (4 digits, e.g. 2009): "). It says what to enter and shows the format.
2Give three qualities of a good error message.
It says what went wrong in plain words, how to fix it, and is polite (no blame, no codes).
3In the menu program, why does get_choice() compare the input with the strings "1", "2", "3" instead of converting it with int() first?
If the user types a letter, int() would crash the program. Comparing strings safely rejects any bad input.
4What does " y ".strip().upper() give, and why is it useful?
"Y". Removing spaces and converting to upper case means y, Y and y are all accepted.
5In the booking program, what happens if the user types 0 hours?
0 < 1, so the loop prints Sorry, you can book 1 to 4 hours. Please try again. and asks again.
6Name two features that make a form user-friendly.
Any two: a clear label for every field; required fields marked; examples or ranges shown; logical order and grouping; errors shown next to the field; a button that says what it does.
7Why should an interface not use colour alone to show an error?
Some users cannot tell certain colours apart (colour blindness), and screen readers do not announce colour. Add words or a symbol as well.
More practice: warm-up
2What should a program do before an action that costs money or deletes data?
Ask the user to confirm it.
3What is input validation?
Checking that input is sensible (right type, allowed range) before using it, and asking again if it is not.
4Why should a menu include a Quit option?
So the user can always leave the program cleanly instead of being stuck or having to force it to close.
5Is ERROR 37 a good error message? Why or why not?
No. It does not say what went wrong or how to fix it.
More practice: on your own
1Write a validation loop that asks for a mark from 0 to 100 and keeps asking until it gets one. (Assume the user types whole numbers.)
mark = int(input("Mark (0-100): "))while mark < 0 or mark > 100: print("Marks must be from 0 to 100. Please try again.") mark = int(input("Mark (0-100): "))
2Rewrite this message to be user-friendly: "Wrong!!! Can't you read?" (The user typed a date in the wrong format.)
Example: "Sorry, that date isn't in the right format. Please type it as YYYY-MM-DD, for example 2026-12-25."
3A menu has options 1 to 5, but option 5 (Quit) is printed at the top and the others are in random order. Suggest two improvements.
Put the options in a logical order with Quit last; keep the numbering in order 1 to 5; add a title; keep the same layout every time the menu is shown.
4In the temperature helper, what does option 2 print for an input of 98.6?
(98.6 − 32) × 5 ÷ 9 = 37.0, so it prints 98.6 F = 37.0 C.
5Explain why while choice not in ("1", "2", "3"): is better than if choice not in ("1", "2", "3"): for validation.
if checks only once, so a second bad answer would get through. while keeps asking until the answer is valid.
Challenge
1Design (on paper) the screens for a text-based library program: a main menu, a "search for a book" screen and a "no results" message. Write the exact text of each.
Example: Main menu: === Maple Library === / 1. Search for a book / 2. My loans / 3. Quit / Choose 1-3:. Search screen: Search by title or author (at least 3 letters):. No results: No books matched "zzz". Check the spelling or try fewer words. A strong answer has titles, numbered choices with Quit, prompts with formats, and an error message that suggests a fix.
2Write a function ask_yes_no(question) that keeps asking until the user types y, yes, n or no (any capitals) and returns True for yes and False for no.
One solution:
def ask_yes_no(question): while True: answer = input(question + " (y/n): ").strip().lower() if answer in ("y", "yes"): return True if answer in ("n", "no"): return False print("Please answer y or n.")
3A sign-up form shows one message at the end: "There were errors." Explain two ways to make it more user-friendly.
Show each error next to the field that caused it, and say what is wrong and how to fix it (e.g. "Grade must be from 9 to 12"). Also keep what the user already typed so they do not have to start over.
Check your understandingQuiz
1. Which prompt is most user-friendly?
2. Which is the best error message?
3. What does " No ".strip().lower() return?
4. Why use a while loop for input validation instead of a single if?
5. Which design choice helps accessibility?
6. In the booking program ($90 per hour), what cost is shown for 3 hours?
For parents and teachersBig idea: B2.5 asks students to design user-friendly software interfaces: prompts, messages, screens and forms. Good interfaces come from empathy for the user and from testing with real people.
How to help: Be the usability tester. Use your teen's program without help and say out loud what you are thinking ("I don't know what to type here"). This is genuinely valuable feedback, and you do not need any programming knowledge.
Common difficulties:
- Prompts that make sense only to the programmer (
Enter n:). - Error messages that are rude, vague or full of codes.
- Checking input with
if once instead of a while loop. - Converting with
int() before checking, which crashes on letters. (The exceptions lesson in this unit shows how to handle that.)