Can someone explain this statement in HW8 recovery assignment text?

Lorenzo_Pellegrino (770 points)
2 5 10
asked Jan 4 in HW8 by Lorenzo_Pellegrino (770 points)
"The test system recognizes recursion ONLY if the recursive function/method is defined in the outermost level.  DO NOT define the recursive function within another function/method otherwise, you will fail all the tests." Does this mean that I can't implement a recursive function inside a class? What are some examples of a recursive function "within another function/method"?

1 Answer

Best answer
andrea.sterbini (172780 points)
514 935 1789
answered Jan 4 by andrea.sterbini (172,780 points)
selected Jan 4 by Lorenzo_Pellegrino
  • external functions: YES
  • methods: YES
  • inner functions (defined inside a function or method): NO

Example of an inner function (see also

def list_of_squares(N):
   def square(x):
      return x*x
   return [ square(i) for i in range(N) ]
Lorenzo_Pellegrino (770 points)
2 5 10
commented Jan 4 by Lorenzo_Pellegrino (770 points)
Thanks Professor. It was very Helpful