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

Do you need help?

Notice Board

Per partecipare al corso di Fondamenti di programmazione 2023-24 loggatevi e attivatelo nella vostra pagina dei corsi preferiti. A quel punto il corso appare nel menù personale cliccando sul proprio avatar. Per i materiali degli anni precedenti seguite lo stesso metodo.

To join the Programming/Lab 2023-24 course, log-on and select it on the my courses page. It will appear on the personal menu of your avatar. For earlier years use the same method.

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"?
260 views
closed

1 Answer

Best answer
andrea.sterbini (207920 points)
750 1267 2373
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