Increment is defined as:
def increment(x):
    return x + 1
The following works, and spits out a result of 8:
def repeated(f, n): 
    def h(x):
        counter = 0
        while counter < n:
            x = f(x)
            counter += 1
        return x
    return h
addthree = repeated(increment,3)
addthree(5)
The following code errors and tells me that i am referencing n before assignment:
def repeated3(f,n): 
    def h(x):
        total=0
        while n != 0:
            total = f(x) + total
            n -= 1
        return total
    return h
addthree = repeated(increment,3)
addthree(5)
why does the error throw when i try to decrement n, even though i am allowed to use it in the logic statement that precedes it?
 
     
     
     
    