Recursion
A recursive function needs a base case that stops and a step that moves closer to it.
Example
def countdown(n):
if n == 0:
return
countdown(n - 1)
Your task
Write factorial(n) recursively and print factorial(5).
DSA & Problem Solving
A recursive function needs a base case that stops and a step that moves closer to it.
def countdown(n):
if n == 0:
return
countdown(n - 1)
Write factorial(n) recursively and print factorial(5).
This lesson is checked against the lesson rules. Your code is never run on our servers.