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.
totalβ the cost of all the notebooks (price * quantity).leftβ how much of yourbudgetis 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
totalon the next line β that's the "remembers" part. Changequantityto5and 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.