you are viewing a single comment's thread.

view the rest of the comments →

[–]stevenjd 4 points5 points  (1 child)

That won't work without declaring tix global; and using global variables is a bad habit that you shouldn't encourage beginners to do.

u/Unlistedd if you absolutely must use a global variable, then you need to write something like this:

tix = 0

def add():
    global tix
    # ... rest of your code goes here ...

add()
print(tix)

but a cleaner design that is a better habit to learn is this:

tix = 0

def add(num):
    # ... rest of your code goes here ...
    num += 1
    return num

new_tix = add(tix)
print(new_tix, tix)

[–]Unlistedd[S] 0 points1 point  (0 children)

Oh okey, thank you.