I've figured out two ways of assigning global variables.
The first method assigns an attribute to a function.
The second method changes a global variable name.
I will be implementing this into a text-based adventure game.
What is the difference between these methods. When is each method commonly used. What method is suitable for my task?
Here is the code.
# Method 1. Assigning attributes to function.
def coin():
print "You see a coin. Pick it up?"
choice = raw_input("> ")
if choice == "yes":
coin.amount = coin.amount + 1
print coin.amount
elif choice == "no":
print "No monies for you."
# Method 2. Assigning global name within function.
def coin2():
global purse
print "You see a coin. Pick it up?"
choice = raw_input("> ")
if choice == "yes":
purse = purse + 1
print purse
elif choice == "no":
print "No monies for you."
coin.amount = 0
coin()
purse = 0
coin2()
Note: Previous answers I've discovered have seem to broad, so I will ask a new question specific to my problem of deciding which is most suitable for a text-based adventure game.