This is Python Lesson 3
Now we are going to focus on variables for this lesson. We are going to take this slowly and explain as we go along. If you remember last lesson we made variables that simply stored 1 number. We are still making variables that hold numbers but they have to calculations to get to those numbers. For example if we wanted to store and print the answer to 7 – 8 in the variable ‘calculation’ we would type:
Now the output to this piece of code is of course -1. Now at this point you might be wondering why don’t we just type 7 – 8 because that would give us the output -1 as well. The reason is that when we use variables it remembers the answer and we can print it again and again. Also we can make a calculation with a variable :
Now this would give us the output 4. The variables in this case are ‘calculation’ and variable_calculation. Don’t be scared of the underscore, that is there because in variables we can’t have spaces so we replace them with underscores. We can also take variables away from each other in a variable!
The output to this is of course 16.0 Now you can use and print more variables experiment with adding, subtracting , multiplying and dividing variables!