What is a variable?
A variable is a named storage space in the computer's memory that holds a value. You give the variable a name, and the value inside it can be read or changed while the program runs. When a new value is assigned, the old value is replaced.
Example
age = 13 creates a variable called age that stores the value 13. Later, age = 14 changes the stored value to 14.
Input and output
Input brings data into the program, usually typed by the user on the keyboard. The value is often stored in a variable. Output sends a result out of the program so the user can see it, for example on the screen. Without input a program cannot receive new data, and without output the user would never see the result.
Example
INPUT price stores the number the user types in the variable price.OUTPUT price then displays that value on the screen.
Input, process, output
Many programs follow the order input, then process, then output: read some data, do something with it, then show the result. Variables hold the values at each stage. Text is stored as a string, and whole numbers as integers, so choosing the right data type helps the program use each value correctly.
Remember
- A variable is a named store for a value that can change.
- Input receives data; output displays a result.
- A common pattern is input, then process, then output.