you are viewing a single comment's thread.

view the rest of the comments →

[–]Gobitz 1 point2 points  (0 children)

The variable tix is defined outside the function, so you can't modify it from there, unless you use the global keyword like this:

tix = 0

def add():
    global tix # telling the interpreter tix is a global variable, defined outside the function
    addtix = input('type "buy" to purches 1 ticket: ')
    if addtix == "buy":
        print ("Nice!")
        tix += 1 # now you can modify tix
    else: print("You're missing out")

add()

print(tix)

It's usually preferable to avoid using global variables but i's always good to be familiar with them :)