Can you tell me where this unassigned global is...I looked everywhere but cannot find it.

global gold
gold = 0
global a_gold_a
a_gold_a = 15
global a_gold_b
a_gold_b = 15
global a_gold_c
a_gold_c = 20
global room1_done
room1_done = 0

def prompt_main():
    global a_gold_a, a_gold_b, a_gold_c, room1_done
    x = raw_input("What do you search? ")
    if x == "couch":
        if a_gold_a == 15:
            a_gold_a = a_gold_a - 15
            gold = gold + 15
            print "You found 15 gold."
            if gold == 50:
                room2()
            else:
                prompt_main()
        else:
            print "There is no more gold in this couch."
            prompt_main()
    elif x == "newspaper":
        print "There is no gold under this newspaper."
        prompt_main()
    elif x == "painting":
        if a_gold_b == 15:
            a_gold_b = a_gold_b - 15
            gold = gold + 15
            print "You found 15 gold behind this painting. How wierd!"
            if gold == 50:
                room2()
            else:
                prompt_main()
        else:
            print "There is no gold anywhere near this painting."
            prompt_main()
    elif x == "lamp":
        print "Nope. No gold by this lamp."
        prompt_main()
    elif x == "desk":
        if a_gold_c == 20:
            a_gold_c = a_gold_c - 20
            gold = gold + 20
            print "You found 20 gold in the desk drawer!"
            
def Main():
    global gold
    print "Your current gold is... ", gold
    print """You are in a large room. You need to find 50 gold to leave this room.
There is a COUCH with a NEWSPAPER on it. There is a PAINTING hanging on the wall
with a picture of a racoon. A LAMP sits on a DESK.
"""
    prompt_main()
    
























def clear():
    print """



































































"""

Thank you!

Recommended Answers

All 2 Replies

If you post the actual error message it will make it a lot easier. I tells us the line in which the error happened

lines 18, 33, 48 for instance
You don't need to declare globals outside the function, just inside the function that uses them.

def test_globals():
    global gold  # <-- this is needed
    for n in range(5):
        gold = gold + 15
        print gold

global gold  # <-- this is not needed
gold = 0
test_globals()

Also this is much simpler ...

def clear():
    print '\n' * 65  # print 65 newlines
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.