Ms. Whitby's Classroom logo Ms. Whitby's Classroom

Values, Variables & Expressions — Lesson 4: Build: Ticket Cost

New skill: Variables and expressions together
Previously learned: Unit 01 — output, execution, and debugging

Why this matters

Real programs calculate new information using values they’ve stored. This mini-project applies your variable and arithmetic skills.

Study this example

items = 2
cost_each = 7
subtotal = items * cost_each
print('Subtotal:', subtotal)

The variable subtotal captures a calculated value, making the code clearer and easier to change. Notice that print separates the label and number with a space.

Before moving on, trace each line of the example by hand. Predict the result before running it in the browser.

Check your understanding

If items becomes 5, which line must change?

Common mistake

Do not hardcode the answer when you can calculate from the given variables.

Practice: Build: Ticket Cost

A club sells 4 passes at $12 each. Define variables passes and price, calculate the total, and display exactly Total: 48.

Expected console output

Total: 48

Starter file: main.py

Use Run to experiment and Check to compare against published examples. A passing public example does not automatically establish mastery.

Hint 1 — Identify the key concept Multiply the number of passes by the price.
Hint 2 — Find an approach You can store the calculation in a `total` variable.
Hint 3 — Check your answer Print a label and the computed value in a single statement.

Reflection

Write a short explanation of why your code works. What input or change would make it behave differently?