Translations of this page:

002 values

step 002

changing variables

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.

source code

click reload on your browser if you see no source code here or visit


Tricky question: How many hitpoints has Grunty left now ?

Find out by either coding in your pyhton shell or online (just click on the graphic):
click on the graphic

The answer is 421)

inspecting variables

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:

step 002
1) If you don't laugh now, you should read this book

en/python/goblins/step002.txt · Last modified: 2014/01/09 11:07 (external edit)