This is the question: Fill in the recursive step in this function, and then find the answer by evaluating
Hint: Remember the definition of factorials and use it to relate and In the code, you will relate factorial(n) and factorial(n-1).
This is the orginal code:
def factorial(n):
# Solve the base case
if n == 0 or n == 1:
return 1
else:
return # How can you reduce this problem?
print(factorial(10))
I read the solution but is not said how the code should look like. I'll appreciate help :)
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
I believe the else line should say
else: return n * factorial(n-1)
Also, aren't the else and return supposed to be indented?