how to change parent function's arguments in high order function in python

def make_repeater(f, n):
  def a(x):
    total = x
    while n > 0:
      total = f(total)
      n -= 1
    return total
  return a

make_repeater(lambda x: x + 1, 3)(5)

get error: UnboundLocalError: local variable 'n' referenced before assignment

how to solve this problem?