LessonΒ·difficulty 1/5Β·~6 min
Shopping total
Python is a calculator that remembers. Store numbers in names, then do math with the names:
python
seats = 4
ticket = 250
bill = seats * ticket # 1000
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.leftβ how much of yourbudgetis left after buying them.
The seats Γ ticket example shows the pattern β apply it with price,
quantity, and budget, then print(total, left). Give it a real go before
asking the tutor for a spark.
Notice you can reuse
totalwhen you computeleftβ 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
β¦ Stuck? Ask for a spark
Sign in or create a free account to use your monthly AI explainer allowance.
warming up
Loading editorβ¦
Consolewaiting
$ Console output will appear here.