Beep! Tap the happy computer!
Python first steps

Is a coding variable the same as algebra’s x?

# Variables store things A **variable** is a named box. ```python name = "Aiden" score = 12 score = score + 1 print(name, "has", score) ``` Rules: - Names can use letters, numbers, underscore - Do not start with a number - Choose meaning: `score` not `x` (unless x is really an x) ## Types you will meet - **int** — whole numbers `7` - **float** — decimals `3.14` - **str** — text `"hello"` - **bool** — `True` / `False` > Changing a variable does not change the past print — only the box’s new value. ## Two meanings of = (do not panic) | Place | = means | | --- | --- | | Algebra equation | both sides have the same value (balance) | | Python assignment | put the right-hand result into the left-hand box | `score = score + 1` is legal in Python and nonsense as a claim that a number equals itself plus one. Different language, same keyboard symbol. When we later write `if score == 10`, the double equals is the **question** “are they equal?” — closer to algebra’s balance. ### Naming Use names that mean something: `marks`, `total`, `name`. `a`, `b`, `x` are fine for tiny maths traces. `asdf` is as bad as a file named asdfg.docx.

By the end of this lesson

Trace a three-line Python script that sets a variable, changes it, and prints it — and say it is the same box as algebra’s x.

Remember

  • A variable is a named box. score = 5 puts 5 in the box called score.
  • The = in Python is “put this into that box”, not the algebra balance (though we still check truth later).
  • print(score) shows what is in the box. print("score") shows the word score.
  • You can update: score = score + 1.
  • Same idea as algebra’s x. Different spelling.

Worked examples

Cover the answer. Try the steps on paper, then open them.

Example 1 — Trace

name = "Asha" print(name)

  1. Box name now holds Asha
  2. print shows Asha, not the word name

Answer: Asha

Check: No quotes around name in print — we want the box, not the label.

Example 2 — Update

score = 4 score = score + 1 print(score)

  1. score starts at 4
  2. score + 1 is 5, put back into score
  3. print shows 5

Answer: 5

Check: The box can change. That is why it is variable.

Example 3 — Two boxes

a = 3 b = 4 print(a + b)

  1. a holds 3, b holds 4
  2. a + b computes 7
  3. print shows 7

Answer: 7

Check: Exactly 3 + 4 in algebra.

Common mistakes

Slip print("score") when you wanted the number in score.

Fix Quotes print the word. No quotes prints the box.

Look at the quotes first when output looks “too wordy”.

Slip Reading score = score + 1 as a lying equation 4 = 5.

Fix In Python = means assign, not “both sides already equal”.

Read it as “new score is old score plus one”.

Slip Using a variable before you set it.

Fix Name the box first.

Sequence lesson again.

Try on paper first

Write the answer, then tap Reveal. These are not the quiz — they are warm-ups.

1. What is in x after x = 10?

Answer: 10

2. What does print("x") show if x = 10?

Answer: the letter x

3. After n = 2 and n = n * 5, n is…

Answer: 10

4. Python = at beginner level mainly means…

Answer: Store / assign into the box

Touch practice

9 tap / type

Tap or type. Use the hint if you need it. Retry any miss — the why is the lesson.

Optional picture lab

After practice

Real world

A labelled box on a shelf.

Connect

x = 5 in maths and in Python.

⭐ Star quiz

9 questions

Do the worked examples and touch practice first. Then take the quiz without peeking.