Variables and Types: Boxes That Remember

Lesson 1 of 1 · 25 min · In Python Expert
[python@expert:~$]
python expert / lesson 02 / variables & types
XP 0/500
STREAK 0
STAGE 1/8
[··········]

variables and types

// boxes that remember — stop recomputing. start storing.
stage 01 / why

your code has amnesia

Last lesson, every calculation vanished the moment Python finished it. If you wanted the answer twice, you typed it twice.

Variables fix that — they're labeled boxes Python remembers. And once you store things, Python suddenly cares what KIND of thing you stored: a number behaves nothing like a piece of text.

A program without variables is a calculator. A program with variables is a memory.
  • Variables let you name a value once and reuse it
  • Python labels every value with a type — and types control what's allowed
stage 02 / watch

watch a variable remember

Three lines. Watch price get reused without retyping 19.99.

price = 19.99 tax = 0.08 total = price + price * tax print(total)
click run to execute

type inspector

price→ float
tax→ float
total→ float
stage 03 / notice

spot the type

age = 30 pi = 3.14 name = 'Ada' is_admin = True
Which list correctly matches each value to its type?
stage 04 / you try

store and reuse

Fill in your name as a string. Then add a line that prints greeting twice (one print per line, or one print with both).

// output will appear here
stage 05 / build

build a tip calculator

Define bill (float), tip_percent (float), diners (int). Compute per-person total using only variables — no magic numbers in the formula. Store the result in per_person and print it.

// output will appear here
stage 06 / debug trap

the '3' + 5 trap

A learner writes:

age = input('Your age: ') # user types 3 next_year = age + 1 print(next_year)
What's actually wrong here?
stage 07 / explain

teach it back

A friend who knows algebra but not programming asks:

Why does Python care whether something is a number or a string? Isn't 3 just 3?

Write a 2–4 sentence reply. Try to mention type, string, int, and why '3' + 5 fails.

stage 08 / boss

boss: ship a receipt printer

Build a mini program that combines str, int, float, and bool. Customer name, item price, quantity, member flag → printed receipt line. Make 3 design calls:

How to read quantity from input()
How to put the total into the print string
How to apply the member discount

compiled.

>>> you're fluent now.

You just built a real receipt printer using int, float, str, and bool together — and dodged three TypeErrors that trip up most beginners. Variables are now your memory, and types are now your friend.

FINAL XP: 0 / 500 · BEST STREAK: 0

// spaced review schedule

+1 day
Rebuild the tip calculator from Stage 5 from a blank screen — no peeking.
+3 days
Take a string of digits like '42', convert it to int, add 8, then convert back to a string for printing.
+1 week
Re-do the boss receipt printer, but add a second item (different price and quantity) and print a grand total.
+2 weeks
Preview next lesson: use an if-statement on the is_member bool from this lesson to print a thank-you line for members only.

Overview

The previous lesson computed values but forgot them. Now we store results in variables and discover that Python treats numbers, strings, and booleans differently. Introduces type errors as a feature, not a bug.

What you'll learn

  • Assign values to variables and reuse them across multiple statements
  • Identify int, float, str, and bool types and convert between them with int(), float(), str()
  • Predict and fix common TypeError situations like '3' + 5

About this tutorial

This lesson is part of the Python Expert tutorial, in the Become a Python Expert Today module.
Last updated May 4, 2026