...

/

Solution Review: The Factorial

Solution Review: The Factorial

Review the solution for the "Factorial' problem."

We'll cover the following...

Solution

Let’s explore the solution to the problem of the factorial.

Press + to interact
def factorial(n):
# Base case
if n == 0 or n == 1:
return 1
if n < 0:
return -1
# Recursive call
return n * factorial(n - 1)
print(factorial(5))

Explanation

Here’s a line-by-line explanation of the code for the factorial problem:

    ...