✕ Close
← Project: Mad Libs

Level 4 · Lesson 32: Practice: the snack shop

Level 4 test: Python Starter →
PRACTICE
The snack shop
Prices, totals and change, all in Python.
press Enter ↵
🐍 main.py
Ctrl + Enter runs it too. Esc, then Tab, leaves the code.
Output

Press ▶ Run to see what your program does.

Lesson 32: Practice: the snack shop

Level 4, Python First Steps. Prices, totals and change, all in Python. It follows lesson 31, Project: Mad Libs. Next comes lesson 33, Level 4 test: Python Starter.

What the lesson explains

The snack shop. Prices, totals and change, all in Python.

What you do first

Add it up. Print the price of 3 apples. The editor opens with: apple = 2 / juice = 3. One way to write it: apple = 2 / juice = 3 / print(apple * 3). It prints: 6.

What you practise

Orders, "Add it up": Print the price of 3 apples. The editor opens with: apple = 2 / juice = 3. One way to write it: apple = 2 / juice = 3 / print(apple * 3). It prints: 6. Then: Print the total of one apple and one juice. The editor opens with: apple = 2 / juice = 3. One way to write it: apple = 2 / juice = 3 / print(apple + juice). It prints: 5. Then: Pay with 10: print the change for one juice. The editor opens with: apple = 2 / juice = 3. One way to write it: apple = 2 / juice = 3 / print(10 - juice). It prints: 7.

Challenge, "The till": Ask how many apples, print the total. The editor opens with: apple = 2. One way to write it: apple = 2 / n = int(input("How many apples? ")) / print("Total: " + str(apple * n)). Answer its question with 4. It prints: How many apples? 4 / Total: 8.

What PlayBuddy and PlayType say

PlayType: "Practice time! The snack shop needs a program. Can you help?"

Help in every lesson

Everything happens on a pretend computer in your browser, so nothing touches your real files. PlayBuddy and PlayType stand beside the board, cheer you on and say when it is your turn.

A green ring shows where to click the first time. After that you do it on your own, and if you slip twice the ring comes back.

Stars

The lesson has 4 things to do. Up to one slip in ten gives three stars, up to one in four gives two, and finishing always gives at least one. Stars and progress are saved in this browser only; there is no account.

About DayOneCode

DayOneCode is an independent learning site, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic.