-2
def function():
    x = 0
    
    def myFunc():
        global x
        
        if x == 1:
           print(str(x))
           x += 1
        else:
           x += 1
           print(str(x))
function()

This is a basic example of the program I'm writing, the result is a NameError. The program runs fine if i assign a value to x inside myFunc(), but I can't because the real project is a game and I'm using this to keep track of a score, so the function will repeat multiple times and thevalue would be reset each time.

0 Answers0