[Tutor] Help

Alan Gauld alan.gauld at btinternet.com
Sat Feb 2 09:35:01 CET 2013

On 02/02/13 01:47, Jack Little wrote:

> def simpstart():
>    global ammo1
>    global ammo2
>    global ammo3
>    global health
>    global tech_parts
>    global exp
>    global radio_parts
>    ammo1=10
>    ammo2=0
>    ammo3=0
>    health=100
>    tech_parts=0
>    exp=0
>    radio_parts=0

This function is completely pointless, you might as well
just define the variables at the top level.

> print "You awake in a haze. A crate,a door and a radio."
> g1 = raw_input("Which do you choose  ")
> if g1 == "CRATE" or g1 == "Crate" or g1 == "crate":
> elif g1 =="DOOR" or g1 == "Door" or g1 == "door":
>        print "You are outside"
> elif g1 == "RADIO" or g1 == "Radio" or g1 == "radio":
> g2 = raw_input("So this is NYC.Ten years after.There are a few
> streets.Go west or north  ")
> if g2 == "WEST" or g2 == "West" or g2 == "west":
>        path2_pt1()
> elif g2 == "NORTH" or g2 == "North" or g2 == "north":
>        path1pt1()

The block above is at top level so Python will execute it as it reads 
the file. And at this stage pathpt1 does not exist so it fails. You need 
to move this block into a function (maybe it was intended to be part of 
the one above but you messed up the indent?). Alternatively you need to 
move the definition of pathpt1 above this block.

> def path1pt1():
>      print "This is where it all started. Freedom Tower. A biotech firm
> called Aesthos Biotechnology. Based here."
>      print "I worked there."

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list