forked from OmkarPathak/pygorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactorial.py
More file actions
34 lines (26 loc) · 673 Bytes
/
factorial.py
File metadata and controls
34 lines (26 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Author: OMKAR PATHAK
Created On: 22 August 2017
"""
import inspect
def factorial(number):
"""
This recursive function calculates the factorial of a number
In math, the factorial function is
represented by (!) exclamation mark.
Example:
3! = 3 * 2 * 1
= (6) * 1
3! = 6
"""
if not isinstance(number, int):
raise Exception('Enter an integer number to find the factorial')
if number == 1 or number == 0:
return 1
else:
return number * factorial(number - 1)
def get_code():
"""
returns the code for the factorial function
"""
return inspect.getsource(factorial)