← Back to course
Code Crew G3 / Week 04 / Monday
1/6
Week 04 Β· Variables

Monday

// Boxes that hold things

Monday: Meet the Idea

"Look at my score box!" Rocket says. It sits on his desk. Right now it holds zero.

Rocket scores a goal. The box now holds one. Then two. Then three.

"What do you notice?" Raven asks. "The name stays the same. The value changes."

Nova glows. "That box is a variable," she says. Let's name a box and give it a value.

ROCKET keeps a box on the desk labeled SCORE. Right now it holds the number 0. When Rocket scores a goal, the box changes to 1. Then 2. Then 3. The box has the SAME NAME but a DIFFERENT VALUE. That box is a VARIABLE.

Big Idea
VARIABLE = a box with a NAME.
The VALUE inside can change.
The name stays the same.

Quick Try

Pick a name for a box. Pick a starting value.

name = __________ value = __________
After 5 minutes I want value = __________

Name and Value

Every variable has two parts. The NAME is the label on the box. The VALUE is what is inside.

When the value changes, the old value is gone. The box holds one value at a time.

lives = 3
lives = 2
print(lives)
READ THE BOX
  • Read the question.
  • Tap your answer.
In lives = 3, what is the name?
In lives = 3, what is the value?
After both lines run, what does print(lives) show?
How many values can one box hold at a time?
stars = 5. What is the value of stars?
Then stars = 8. What is the value of stars now?
What is the name of this variable?
StatementTrue or false?
A variable has a name and a value.?
The name changes when the value changes.?
A new value replaces the old value.?
color = blue puts the value blue in the box named color.?
A variable can hold two values at the same time.?
WHY THIS EXERCISEVariables let a program remember things that change, like a score.
TRACK THE SCORE
  • ?Rocket scores, so score = 1
  • ?Raven scores, so score = 2
  • ?score = 0
  • ?Rocket scores, so score = 3
WHY THIS EXERCISEA variable changes over time. Each new line updates the box.
pets = 2. A new kitten comes home. What is pets now?
WHY THIS EXERCISEWhen something in the world changes, the program updates its variable.
Try it
Find a cup and some paper. Write a name on the cup, like steps.
Drop in a paper slip with a number on it.
Change the value: swap the slip for a new number.

Quick Check

A box is named score. It holds 3. What is the box's NAME? ____
Same box. What is its VALUE? ____
Rocket scores one more goal. What is the value now? ____