I am having trouble implementing this in Python. I want to write a function with (sole) input n, that recursively generates a list of factorial values 1! ... n!
So far I have thought of storing the recursively derived values of n-factorial in a variable, and then adding (pushing?) them into a list. The question I have is how do I 'save' the list? I am not sure how to check if a list exists or not as well...
def recFactorial(n):
if n == 1:
return 1
print(l)
else:
l = []
f = n * recFactorial(n-1)
if l:
l = l.push(f)
else:
l = []
解决方案
Recursive function calls can't see the local variables of the other calls to the same function. If you want several calls to be able to work with the same list, the list needs to either be a par