Recursive function required scope

Dario_loi (1710 points)
0 3 10
asked Dec 5, 2020 in HW8 required by Dario_loi (1,710 points)
In our homework's specifications, it is noted that our recursive function must be defined in the "outermost level"

is it correct to assume that it therefore must be declared in the global scope?

my question is, does a class count as an 'inner level' from the global scope, and in that case, if I declare my recursive function as a method of that class, will it not be counted as such?

2 Answers

Best answer
Silktrader (2550 points)
1 6 16
answered Dec 5, 2020 by Silktrader (2,550 points)
selected Dec 5, 2020 by Dario_loi

You can check which global scope functions, classes are defined by running dir on the program01 module. From the Python console:

import program01

You will read the list of functions, classes in the module's outermost scope. If you're working with Spyder, set the console's working directory or call dir from within the program01 module.

I may be wrong, but class methods don't count as recursive functions for our purpose.

Class methods count as recursive functions for our purpose.

Silktrader (2550 points)
1 6 16
commented Dec 5, 2020 by Silktrader (2,550 points)
Ah! I was wrong. Whoever wrote the tests is actually iterating the module's classes and decorating their methods with the attributes required to tell whether it's recursive. Check "", line #66 and decorators.

So class methods seem to count as possible recursive functions.
Francesco.Danese (2130 points)
0 1 9
answered Dec 5, 2020 by Francesco.Danese (2,130 points)


Design and implement the function ex1(instructions_file, initial_city, clues)
recursive or using recursive functions or methods, which receives as

So yes, you can use recursive methods.