Skip to content

Commit bd269f2

Browse files
committed
Added factorial implementation (recursive)
1 parent 305d1f9 commit bd269f2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pygorithm/math/factorial.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Author: OMKAR PATHAK
3+
Created On: 22 August 2017
4+
"""
5+
6+
def factorial(number):
7+
''' This function calculates the factorial of a number '''
8+
if not isinstance(number, int):
9+
raise Exception('Enter an integer number to find the factorial')
10+
if number == 1 or number == 0:
11+
return 1
12+
else:
13+
return number * factorial(number - 1)
14+
15+
def get_code():
16+
"""
17+
returns the code for the factorial function
18+
"""
19+
return inspect.getsource(factorial)

0 commit comments

Comments
 (0)