Thanks Kent for your reply.
You said
This is a limitation of Python's nested scopes. You can't assign to a variable in an enclosing
scope. One way to work around this is to use a mutable value like a list in the enclosing scope:
def foo (n):
counter = [0]
def choose (i):
if (solution
Hello list
I am having trouble with a variable to act as a counter in a nested
recursive function which will only occasionally find an answer.
Something like a static variable in C.
Why does this sort of thing not work?
def foo (n):
counter = 0
def choose (i):
if (solution found):
Logesh Pillay wrote:
Hello list
I am having trouble with a variable to act as a counter in a nested
recursive function which will only occasionally find an answer.
Something like a static variable in C.
Why does this sort of thing not work?
def foo (n):
counter = 0
def choose (i):