During a game of goblin dice duel, each hit on the head will decrease the victim's remaining hitpoints.
Let's assume that Stinky swings his club and hit Grunty over the head so that Grunty looses one hitpoint ( or hitting him for 1 point of damage).
In python, this is done by writing either:
hitpointsGrunty = hitpointsGrunty - 1
or more common because less to type:
hitpointsGrunty -= 1
In both cases, the python interpreter will first calculate the right side of the equation (hitpointsGrunty - 1) and assign the result to the variable on the left side of the equation….hitpointsGrunty. The old value of the variable is overwritten.
click reload on your browser if you see no source code here or visit Github.com
Tricky question: How many hitpoints has Grunty left now ?
The answer is 421)
If you click the grey “forward” button on the online example above you can see how the values of the variables change each time. IF you work with the python shell, you must tell python to show the value of a variable by typing the variable name:
Do this in the python shell:
Later, you will learn other methods to inspect variables, like the print() function and how to work with debuggers.
Generally, if you want to print the value of a variable, you code: