Students read a working café till, predict a change, then build a console app with a menu, a checked number and a total.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 8 min · Investigate 8 min · Modify 8 min · Make 20 min
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Work out the total on paper with your partner. Compare before you run.
Show your app to another pair. They try it, including a wrong input, and tell you one thing that works well and one that could be better.
Planning before typing. Ask for the choices and what ends the program.
| What you will see | A question to ask | The fix |
|---|---|---|
| The menu never ends. | Which line runs break? | One branch needs a break, indented inside the loop. |
| A crash when a word is typed for a quantity. | Is int called before or after the isdigit check? | Check inside an if first, and convert inside it. |
One possible solution for each task. Other correct programs are fine.
total = 0
while True:
choice = input("1 coffee $4, 2 cake $5, 3 sandwich $7, 4 pay: ")
if choice == "1":
total += 4
print("Coffee added. Total: $" + str(total))
elif choice == "2":
how_many = input("How many cakes? ")
if how_many.isdigit():
total += 5 * int(how_many)
print("Cakes added. Total: $" + str(total))
else:
print("Please type a number.")
elif choice == "3":
how_many = input("How many sandwiches? ")
if how_many.isdigit():
total += 7 * int(how_many)
print("Sandwiches added. Total: $" + str(total))
else:
print("Please type a number.")
elif choice == "4":
break
else:
print("Please choose 1, 2, 3 or 4.")
print("Please pay $" + str(total))
total = 0
while True:
choice = input("1 pencil $2, 2 ruler $3, 3 pay: ")
if choice == "1":
amount = input("How many pencils? ")
if amount.isdigit():
total += 2 * int(amount)
print("Total: $" + str(total))
else:
print("Please type a number.")
elif choice == "2":
total += 3
print("Total: $" + str(total))
elif choice == "3":
break
else:
print("Please choose 1, 2 or 3.")
print("Please pay $" + str(total))
Stretch: Save the order to a list and print every item at the end.
Support: Give the café with one branch missing and ask for it.
Name three moves your app uses and the line that shows each.
Any three of: input, int with isdigit, while True with break, +=, if/elif/else, a function.
The Python extensions all start here: objects, data detective, deeper console Python, and apps with Gradio.