Understanding Variables in Programming
YEAR 6
Understanding Variables in Programming
YEAR 6
Learning Objective
At the end of the lesson, you will understand variables, explore
inputs and
outputs, and
create a simple program using variables.
What do you already know about variables in programming?
What is a Variable?
A variable is a named space in memory to store data.
It helps in organising and managing data in a program.
Importance of Variables
Variables allow storing, retrieving, and manipulating data. They make programs dynamic and flexible.
Inputs in Programming
Inputs are data provided to a program. They can be stored in variables for processing.
Outputs in Programming
Outputs are data produced by a program. They often come from variables and show results to the user.
Variables in Action
A program can take input, store it in a variable, process it, and then output the result.
Creating a Simple Program
Let's write a program that uses a variable to store your name and greet you.
# This program asks for your name, stores it in a variable, and greets you
# Ask the user to enter their name
# Display a personalised greeting
name = input("What is your name? ")
print("Hello, " + name + "! Welcome to Python programming.")
How it works:
input("What is your name? ") pauses the program and waits for the user to type their name.
The name entered is stored in the variable name.
The program then prints a friendly greeting using that name.
# This program greets the user with a time-based message and emojis
import datetime
# Ask for the user's name
name = input("What is your name? ")
# Get the current hour
current_hour = datetime.datetime.now().hour
# Decide the greeting based on the time of day
if current_hour < 12:
greeting = "Good morning 🌞"
elif current_hour < 18:
greeting = "Good afternoon ☀️"
else:
greeting = "Good evening 🌙"
# Display the personalized greeting
print(f"{greeting}, {name}! Welcome to Python programming 💻")
How this version works:
It imports the datetime module to check the current time.
It chooses the right greeting — morning, afternoon, or evening.
It uses f-strings (formatted strings) for cleaner output.
It adds friendly emojis to make the interaction more engaging.
What is a variable in programming?
A storage location for data
A user interface element
An algorithm step
A type of programming language
What are inputs in a program?
Data provided by the user
The final output of the program
Errors in the code
Code written by the programmer
What does an output represent?
The program's source code
A variable's value
Data entered by the user
Results produced by a program
Which is an example of a variable?
userAge
totalScore
for loop
print()
What is the purpose of variables?
To store information temporarily
To create user interfaces
To display outputs
To define functions
Review and Reflect
What did you learn about variables, inputs, and outputs today?
Ask 1 question about something you haven't quite understood yet.