Recursion of function defined within another function

Stephan Tolksdorf andorxor at
Thu Nov 9 20:23:19 CET 2000


Why does the following program raises this error:


Traceback (most recent call last):
  File "D:\projects\python\xrtt\", line 9, in ?
    print Recur()
  File "D:\projects\python\xrtt\", line 7, in Recur
    return inner(0)
  File "D:\projects\python\xrtt\", line 4, in inner
    if i < 100: return inner(i)
NameError: There is no variable named 'inner'


def Recur():
    def inner(i):
        i = i + 1
        if i < 100: return inner(i)
        else: return i 
    return inner(0)

print Recur()


Best regards,
  Stephan Tolksdorf

More information about the Python-list mailing list