MCPcopy Create free account
hub / github.com/geekcomputers/Python / factorial

Function factorial

FIND FACTORIAL OF A NUMBER.py:4–12  ·  view source on GitHub ↗
(n)

Source from the content-addressed store, hash-verified

2
3
4def factorial(n):
5 if n < 0: # factorial of number less than 0 is not possible
6 return "Oops!Factorial Not Possible"
7 elif (
8 n == 0
9 ): # 0! = 1; when n=0 it returns 1 to the function which is calling it previously.
10 return 1
11 else:
12 return n * factorial(n - 1)
13
14
15# Recursive function. At every iteration "n" is getting reduced by 1 until the "n" is equal to 0.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected