Recursion

  • Must have a stopping condition
    • called a base case
  • recursive call
    • how does this bring you to the base case?
def factorial(x):
    """This is a recursive function
    to find the factorial of an integer"""
    if x == 1:
        return 1
    else:
        return (x * factorial(x-1))
num = 3
print("The factorial of", num, "is", factorial(num))

Questions

  • how many times is the function called?
  • what is done to reach the base case?