Variable
A Variable is something that can be changed
Ex:1
sigma=1950
hypnoDance=546
views=sigma+hypnoDance
print(views)
***Explanation
The 1st variable sigma is storing 1950
The 2nd variable hypnoDance is storing 546
The 3rd variable views is storing the addition of 1st and 2nd variables
So, the output will give us what is inside the 3rd variable views
Ex:2
name=15
name=10
print(name)
***Explanation
Here we have only one variable which is called name.
● At first we stored in variable name 15
● And then we stored in that same variable 10
The program will output the last stored data. So, the output will be 10.
Changing the value in a variable
Ex:1
***Explanation
Initially we stored 1 in a variable number
Output will be 1
And then we ordered to add 1 to what was already inside. So
output will be 2
Output will be 2
And then we ordered again to add 1 to what was already inside. So
output will be 3
Output will be 3
And so on…
***Explanation: The last output and the first output look similar but the
python program reads from beginning and looks for what stores originally
variable and then what kind of changes happened to that variable.
Ex:2
Write a new program to
output a countdown from 3
to 1.
Homework
Ex:1
Write a statement(code) to output your name.
Ex:2
number=5
number=number+1
print(number) what is the output? _________
number=number+3
print(number) what is the output? _________
number=number-2
print(number) what is the output? _________
number=number+5
print(number) what is the output? _________