Lesson 2: Variables – Teaching Computers to Remember Information
What is a Variable?
Imagine you have a school bag where you keep your books, pencils, and notebooks. Whenever you need something, you know exactly where to find it.
A variable works in a similar way. It is like a special box or container inside the computer where we can store information.
The computer remembers what we put inside the variable until we change it.
Why Do We Use Variables?
Variables help computers remember information such as:
- 👦 A student’s name
- 🎂 Age
- 🏫 School name
- 📚 Favorite subject
- 🎮 Game score
- 💰 Money
- ⭐ Points earned
Without variables, every program would have to repeat the same information again and again.
Real-Life Example
Imagine your teacher asks everyone in class to write their name.
Instead of creating a different program for every student, we can use a variable.
For example:
name = "Ali"
Here,
- name is the variable.
- Ali is the value stored inside it.
The computer now remembers the name.
Printing a Variable
We can tell Python to display the stored information.
name = "Ali"
print(name)
Output
Ali
Instead of writing the name directly, Python looks inside the variable and prints its value.
Storing Different Types of Information
Name
student = "Ayesha"
print(student)
Output
Ayesha
Age
age = 10
print(age)
Output
10
School Name
school = "City School"
print(school)
Output
City School
Multiple Variables
We can store many pieces of information.
name = "Ali"
age = 11
school = "ABC School"
print(name)
print(age)
print(school)
Output
Ali
11
ABC School
How AI Uses Variables
Artificial Intelligence remembers information using variables.
For example, an AI chatbot may store:
- Your name
- Your question
- Your language
- Your favorite subject
Variables help AI give better answers.
Mission 2
Open the Python Studio and write this program.
name = "Your Name"
school = "Your School"
print(name)
print(school)
Challenge
Replace:
- Your Name with your own name.
- Your School with your school’s name.
Run the program and see your information displayed on the screen.
Activity
Think about three things you would like the computer to remember.
Write them here.
Did You Know?
Every game you play uses variables.
Your score, coins, health, level, and player name are all stored in variables while the game is running.
⭐ Lesson Summary
Today you learned:
- ✅ What a variable is.
- ✅ How variables store information.
- ✅ How to create variables in Python.
- ✅ How to print variables.
- ✅ How AI uses variables to remember information.
- ✅ How to write your own variable program.
🎉 Fantastic work! You have now taken another step toward becoming a young Python programmer.