Variables

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Variables

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What does x = 5 do?
A Checks if x equals 5
B Stores 5 in x
2. After name = 'Alice', what is stored in name?
A Alice
B name
3. Which is correct assignment?
A age = 15
B 15 = age
4. What does = mean in Python?
A Assign
B Equality
5. After score = 100, what is stored in score?
A score
B 100

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
13name = 'Bob' AOutput: 10
2my-score = 5 BValid: Number after first char
3name3 = 'Bob' CValid: Underscore ok
4my_score = 5 DError: Starts with number
5x = 10 print(x) EError: Hyphens not allowed
6name = 'Alice' print(name) FOutput: Alice

Definitions

name = 'Alice'

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
____ = 'Bob' print(name)
2.
age _ 15 print(age)
3.
score = 100 print(_____)
4.
city = 'Melbourne' print(____)
5.
___ = input('Enter Age: ') print(age)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A name = 'Alice'
B age == 15
C print(name)
Question 2
A name = 'Bob'
B 2score = 100
C print(name)
Question 3
A name = 'Alice'
B age = 15
C print('name')
Question 4
A age = 16
B student-name = 'Charlie'
C grade = 11
D print(student-name)
Question 5
A name = 'Diana'
B age = 15
C school = Parkdale High
D print(school)

Answer Key

Variables
Section A: Quick Questions
Q1
B — Stores 5 in x
Q2
A — Alice
Q3
A — age = 15
Q4
A — Assign
Q5
B — 100
Section B: Match the Pairs
Q1
3name = 'Bob' → Error: Starts with number
Q2
my-score = 5 → Error: Hyphens not allowed
Q3
name3 = 'Bob' → Valid: Number after first char
Q4
my_score = 5 → Valid: Underscore ok
Q5
x = 10 print(x) → Output: 10
Q6
name = 'Alice' print(name) → Output: Alice
Section C: Definitions
Q1
name = 'Alice' — Variables store values using = (assignment operator)
Section D: Fill in the Blanks
Q1
name = 'Bob' print(name)
Q2
age = 15 print(age)
Q3
score = 100 print(score)
Q4
city = 'Melbourne' print(city)
Q5
age = input('Enter Age: ') print(age)
Section E: Spot the Error
Q1
B — Line 2 uses == (comparison) instead of = (assignment). Should be: age = 15
Q2
B — Line 2 starts with a number. Variable names cannot start with numbers. Should be: score2 = 100
Q3
C — Line 3 prints the string 'name' instead of the variable. Should be: print(name)
Q4
B — Line 2 uses hyphens which aren't allowed in variable names. Should be: student_name = 'Charlie'
Q5
C — Line 3 is missing quotes around the string value. Should be: school = 'Parkdale High'