[Tutor] Umm.. I need help on changing Global Variables.

Alan Gauld alan.gauld at btinternet.com
Thu Jan 29 23:26:11 CET 2015


On 29/01/15 17:16, Tallen Grey Smith wrote:

> def game():
>
>      global level
>      global player_health
>      global enemy_health
>      global steps
>      global civilians
>      global charge
>

This is fine.
But it only tells this function to treat them as globals.

> def charge_1():
>
>      level
>      player_health
>      enemy_health
>      steps
>      civilians
>      charge

This does nothing useful.
You need to tell the function that they are global just as
you did above. Global variables are considered bad practice
so Python doesn't make it easy to use them. (Although a
lot easier than some languages)

There are quite a few other things we could comment on in your
code but this should resolve the immediate issue.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list