Step 1: The menu board: a NameError
Press Run. The menu board crashes, and Python prints a traceback: its account of what it was doing when it stopped. This one has four parts. Read them from the bottom up:
Traceback (most recent call last):
File "/home/labuser/menu.py", line 6, in <module>
print(f"Flat white: £{pirce // 100}.{pirce % 100:02d}")
^^^^^
NameError: name 'pirce' is not defined. Did you mean: 'price'?
- The last line names the error and what went wrong. A
NameErrormeans the script used a name Python has never seen. Python even guesses what you meant. - The arrows
^^^^^sit under the exact spot on the line. - The line above them is the code Python was running.
line 6says where that code lives inmenu.py.
Go to line 6 of menu.py, fix the name, and press Run until the board prints:
Menu
Flat white: £3.20
Then press Check. Most bugs are found exactly like this: last line first, then the line number.
menu.py, the file you edit6 lines
# The menu board. It runs at opening time and prints today's prices (in whole pennies).
flat_white = 320
price = flat_white
print("Menu")
print(f"Flat white: £{pirce // 100}.{pirce % 100:02d}")