Lesson 4 of 8 · 30 min · Grades 6–8
Doing maths with named values
At the city museum, a child ticket is ₹40. Three friends pay together. The cashier could add 40 three times, or multiply. Python should do the multiply — not because it is fancy, but because when a fourth friend joins you change one number (qty) instead of rewriting the whole bill.
Museum ticket window
Price × quantity is a real bill.
You will be able to
- ✓ Use +, -, * and / on numbers
- ✓ Store a calculated total in a variable
- ✓ Update one input and re-run to get a new bill
Operators are verbs for numbers
+ adds, - subtracts, * multiplies, / divides. In Python, * is never a decorative star — it always means multiply. Write 40 * 3, not 40x3.
Division / gives a fractional result in full Python (120 / 8 is 15.0). For beginner bills we mostly multiply and add. Store the result: total = price * qty so you can print it twice without typing the formula twice.
Name the inputs, not only the answer
A program that says print(120) is a dead poster. A program that says price = 40; qty = 3; print(price * qty) is a living cashier. Tomorrow the ticket price changes — you edit one line.
This is the same idea as a spreadsheet: cells have meaning. In Python the “cells” are variable names. Professionals still do this in large systems; they just have more names.
Brackets control order
Like maths class: 2 + 3 * 4 is 14, not 20, because multiply happens before add. Use brackets when you mean “add first”: (2 + 3) * 4 is 20.
When a formula is long, brackets also make it readable for humans. Readable beats clever.
Discount then tax — named steps
price = 200
discount = 20
pay = price - discount
print("Pay", pay)
Words that matter
- Operator
- A symbol that computes, like * or +.
- Expression
- A mix of values and operators that produces a value.
- Hard-coding
- Writing 120 instead of price * qty — brittle when inputs change.
Common mistakes
Avoid: Using x for multiply (40x3).
Do this: Use * : 40 * 3.
Avoid: Printing only the final number with no labels.
Do this: print("Total rupees", total) so a human can audit the bill.
Example program — Museum tickets
Set qty = 4 and Run. You did not rewrite the formula — only the quantity bag.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Your turn — Canteen bill
A samosa costs 15 rupees. Buy 4. Print the total 60.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Self-assessment
Check your understanding before you mark the lesson complete.
Progress is stored in a browser cookie on this device.