...

/

Solution Review: Factorial of a Number

Solution Review: Factorial of a Number

This lesson will explain the solution to the factorial exercise in the previous chapter lesson.

We'll cover the following...

Solution

Press + to interact
def factorial(n):
# Cover base cases
if n==0 or n==1:
return 1
if n < 1:
return -1
# multiply all postiive integers below n
product = 1
while(n > 1):
product = product * n
n = n-1
return product
print(factorial(5))

Explanation

The function starts ...

Access this course and 1400+ top-rated courses and projects.