Solution Review: The Factorial
Review the solution for the "Factorial' problem."
We'll cover the following...
We'll cover the following...
Solution
Let’s explore the solution to the problem of the factorial.
Python 3.10.4
def factorial(n):# Base caseif n == 0 or n == 1:return 1if n < 0:return -1# Recursive callreturn n * factorial(n - 1)print(factorial(5))
Explanation
Here’s a line-by-line explanation of the code for the factorial problem: