# ThePythonGameBook

learn Python. Create Games

### Sidebar

en:python:goblins:step002

This is an old revision of the document!

## 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 Github.com

#### test

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):

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:

`>>>hitpointsGrunty`

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:

`print(hitpointsGrunty)`
 ← step 002 ↑ →
1)
If you don't laugh now, you should read this book
/var/www/horst/thepythongamebook.com/data/attic/en/python/goblins/step002.1504448474.txt.gz · Last modified: 2017/09/03 16:21 by Horst JENS