Complete the code to define the base case for the factorial function.
def factorial(n): if n == [1]: return 1 else: return n * factorial(n - 1)
The base case for factorial is when n is 0, returning 1.
Complete the code to correctly call the recursive case in the Fibonacci function.
def fibonacci(n): if n <= 1: return n else: return fibonacci([1]) + fibonacci(n - 2)
The recursive case calls fibonacci(n - 1) and fibonacci(n - 2) to sum previous two numbers.
Fix the error in the recursive sum function by completing the base case condition.
def recursive_sum(lst): if len(lst) == [1]: return 0 else: return lst[0] + recursive_sum(lst[1:])
The base case is when the list is empty (length 0), returning 0 to stop recursion.
Fill both blanks to complete the recursive function that counts down from n to 1.
def countdown(n): if n [1] 0: return else: print(n) countdown(n [2] 1)
The base case checks if n is greater than 0 to continue. The recursive call subtracts 1 each time.
Fill all three blanks to complete the recursive function that reverses a string.
def reverse_string(s): if s == [1]: return s else: return s[[2]] + reverse_string(s[:[3]])
The base case is an empty string. The recursive call takes the last character and adds the reverse of the rest.
