Skip to content

Week 19 — Variables & input — programs that talk back

At a glance

Date Friday, January 15, 2027
Unit 3 — From Blocks to Text
Big idea Variables give a program memory; input lets the player change what happens.
Goal Students edit a working Python program so a button press changes a stored value and the sprite reports it.
Student accounts needed None. MakeCode Arcade runs in the browser without sign-in.
Prep time 5 minutes

Why this lesson looks the way it does

The title says input, but in this mixed-age room it does not need to mean keyboard forms. Arcade button presses are input, and they keep the focus on the programming idea instead of typing mechanics. Variables were already familiar from score and lives in blocks. Today students see the same idea in text: a name, an equals sign, and a value. Starters modify a working counter; Builders add a second input; Extenders track more than one value.


CSTA 2026 standards

Concept area Connection
Algorithms & Design Input changes the path and output of a program
Programming Variables store values that programs can update and display
Data & Analysis Data values can be named, changed, and interpreted by the user
Systems & Security Local browser projects can run without collecting student account information
Computing & Society Students explain how user input changes a program's behavior

"I can…" objectives

By the end of today, students can say:

  • I can explain that a variable is a name for a stored value.
  • I can use = to put a value into a variable.
  • I can make a button press change a variable.
  • I can test whether my program changed the value I expected.

Teacher prep — the 5-minute version

  1. Open MakeCode Arcade and switch to Python.
  2. Paste the Starter counter code from the challenge section.
  3. Write on the board: = means store this value; it does not mean equal in Python.
  4. Pair Driver/Navigator; swap at 0:24.

Minute-by-minute run sheet

0:00–0:04 — Anchor

"Last Friday we learned that Python is the same program ideas written with text. Today the program gets memory. When the player presses a button, a number will change. That button press is input."


0:04–0:12 — Mini-lesson

Run this on the projector, then flip briefly to Blocks so students see the same event and variable.

energy = 0
hero = sprites.create(img("""
    . 4 4 .
    4 4 4 4
    . 4 4 .
"""), SpriteKind.player)
hero.say_text("Energy: " + str(energy))

def on_a_pressed():
    global energy
    energy = energy + 1
    hero.say_text("Energy: " + str(energy))
controller.A.on_event(ControllerButtonEvent.PRESSED, on_a_pressed)

"energy = 0 gives the program a memory box named energy. Pressing A changes what is inside the box. str(...) turns the number into text so the sprite can say it."


0:12–0:36 — Paired build

"Run first. Change one thing. Test again. Driver types; Navigator reads and predicts. Swap halfway."

Tiered challenges

🟢 Starter (grades 5–6): change working code

Change the starting number and label.

energy = 5
hero = sprites.create(img("""
    . 4 4 .
    4 4 4 4
    . 4 4 .
"""), SpriteKind.player)

def on_a_pressed():
    global energy
    energy = energy + 1
    hero.say_text("Power: " + str(energy))
controller.A.on_event(ControllerButtonEvent.PRESSED, on_a_pressed)

🟡 Builder (grades 7–8): use the template

Add a B button that subtracts energy.

energy = 3
hero = sprites.create(img("""
    . 6 6 .
    6 6 6 6
    . 6 6 .
"""), SpriteKind.player)

def show_energy():
    hero.say_text("Energy: " + str(energy))

def on_a_pressed():
    global energy
    energy = energy + 1
    show_energy()
controller.A.on_event(ControllerButtonEvent.PRESSED, on_a_pressed)

🔴 Extender (grades 9–10): write from scratch or add features

Track two variables and display both.

energy = 3
coins = 0
hero = sprites.create(img("""
    . 8 8 .
    8 8 8 8
    . 8 8 .
"""), SpriteKind.player)

def report():
    hero.say_text("E:" + str(energy) + " C:" + str(coins))

Add button events so A changes energy and B changes coins.


0:36–0:42 — Share-out

"Show one button press. Before you press it, tell us what value should change. After you press it, prove whether you were right."


0:42–0:45 — Teaser + prompt

"Next Friday the program will make decisions. It will ask: is this value high enough?"

🤔 Think About This

Notice one system this week that remembers a number for you. A score, unread messages, steps, or battery percent. What is the variable?


Share-out prompt

"Show one button press. Before you press it, tell us what value should change. After you press it, prove whether you were right."


🔌 Unplugged Plan B — if the internet is down

Time Activity
0:00–0:04 Anchor: last week text code; today memory and input.
0:04–0:12 Put a box on the board labeled energy. Start at 0. Student button cards A and B change it.
0:12–0:24 Pairs trace paper code: energy = 0, PRESS A, energy = energy + 1, SAY energy.
0:24–0:34 Groups design their own variable box and two inputs. Another group acts as the computer.
0:34–0:42 Share one trace and one Navigator-caught mistake.
0:42–0:45 Same teaser and Think About This.

Common problems & fixes

Problem What students may see Fix
Forgetting global energy UnboundLocalError: cannot access local variable 'energy' where it is not associated with a value Put global energy first inside the function that changes it.
Using == when assigning SyntaxError: invalid syntax For storing a value, use one equals sign: energy = energy + 1.
Mismatched quotes SyntaxError: unterminated string literal Check the text before and after + str(energy).
Missing parenthesis SyntaxError: '(' was never closed Count parentheses out loud.
Button does nothing no error Confirm the event line uses controller.A.on_event(...) and simulator focus.

Vocabulary

  • Variable — a name for a value the program stores
  • Value — the information currently stored in a variable
  • Input — information the program receives, such as a button press
  • Assignment — using = to store a value
  • Event — code that runs when something happens

Reflection — fill in after class

  • Did students understand = as storage, not equality?
  • Which pairs explained the value before and after input?
  • Was global manageable with the template?
  • Who is ready to write event code from scratch?

Next week: Week 20 — Conditionals in text