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

Do you need help?

Recursive function required scope

Dario_loi (1710 points)
1 4 10
in HW8 required by (1.7k 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?
241 views
closed

2 Answers

Best answer
S
Silktrader (2550 points)
2 6 16
by (2.6k points)
selected by

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

import program01
dir(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.

S
Silktrader (2550 points)
2 6 16
by (2.6k 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 "isrecursive.py", line #66 and decorators.

So class methods seem to count as possible recursive functions.
Francesco.Danese (2140 points)
0 1 10
by (2.1k points)

From programo1.py:

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

So yes, you can use recursive methods.