Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Can someone explain this statement in HW8 recovery assignment text?

Lorenzo_Pellegrino (820 points)
2 6 10
in HW8 by (820 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"?
274 views
closed

1 Answer

Best answer
andrea.sterbini (208020 points)
756 1270 2377
by (208k points)
selected by
  • 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 (820 points)
2 6 10
by (820 points)
Thanks Professor. It was very Helpful