in questions 2 and 3 you are asked to give a recursive implementation and then improve it. when making improvements, you may wish to pass on additional parameters to the recursive function. this should be done according to the following guidelines:
1. do not change the prototype (signature) of the main function you were asked to write (not even by adding optional parameters with default values). this may lead your program to fail the automatic scripts that test your homework. it is also conceptually wrong (the additional parameters are of no concern to the user).
2. instead write a helper function which accepts the additional parameters and then operates recursively. the main function will call the helper function instead of performing the recursion by itself (this is allowed).
3. Helper functions usually make the code simpler and more modular. they are generally encouraged. when asked to write a function that performs a specific task, you are allowed to write helper and sub-functions, unless explicitly requested not to.
example recursive code with a helper function:
def func(n): # original prototype # some code... extra1 = 1 extra2 = 2 funcHelper(n,extra1,extra2) # more code... def funcHelper(n,extra1,extra2): # some code... funcHelper(n+1,extra1-1,extra2-1) funcHelper(n-1,extra1+1,extra2+1) # more code...
please note that this issue was discussed extensively in the forum. do try to keep up to date with the forum, we are often asked the same questions over and over again.