Fill up this feedback form
What is a variable
Use of variable in programming
Plan your code to store important data
Allow the data to be used in many places at the same time
Allow the data to be updated & modified easily
Imagine you have a magic box. This box can hold one thing at a time—maybe a number, a word, or a secret code. To make sure you don't forget what's inside, you stick a label on the outside of the box.
In programming, a Variable is just like that labelled box.
In programming, a Variable is just like that labelled box.
The Box: The memory where the information is kept.
The Label: The Name of the variable (e.g., Score).
The Stuff Inside: The Data or Value (e.g., 100).
Storage: We can save things for later (like a player's name).
Reuse: We can use the same "label" many times in our code.
Change: We can easily swap the "stuff inside" the box. If you gain a point, we take out the old score and put in a new, higher one!
Imagine you are building a simple game. You need to keep track of:
The Player's Name
How many lives they have left
Whether the game is over (True or False)
Task: Write down what you would name these variables and what data they might hold at the start of the game.
Example: playerName = "Zul"