← Practice
πŸ“– Numbers and arithmeticshopping-total
LessonΒ·difficulty 1/5Β·~6 min

Shopping total

Shopping total

Python is a calculator that remembers. Store numbers in names, then do math with the names:

python
price = 45
quantity = 3
total = price * quantity   # 135

Your task

You're buying 3 notebooks at β‚Ή45 each, and you walked in with a budget of β‚Ή200.

  1. total β€” the cost of all the notebooks (price * quantity).
  2. left β€” how much of your budget is left after buying them (budget - total).
python
price = 45
quantity = 3
budget = 200

total = price * quantity
left = budget - total
print(total, left)

Notice you can reuse total on the next line β€” that's the "remembers" part. Change quantity to 5 and re-run to see both numbers update.

Tests

  • total is 3 notebooks x 45
  • left is the budget minus the total
  • total really is price times quantity (hidden)

✦ Stuck? Ask for a spark

warming up
Loading editor…

$ Console output will appear here.

>_AI tutor
Sign in to chat with the tutor.