Can someone explain this statement in HW8 recovery assignment text?

Lorenzo_Pellegrino (770 points)
2 4 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"?
124 views

1 Answer

Best answer
andrea.sterbini (172340 points)
510 927 1776
answered Jan 4 by andrea.sterbini (172,340 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 https://www.google.com/search?q=python+inner+functions)

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