Skip to content

Commit

Permalink
Added factorial implementation (recursive)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmkarPathak committed Aug 23, 2017
1 parent 305d1f9 commit bd269f2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pygorithm/math/factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Author: OMKAR PATHAK
Created On: 22 August 2017
"""

def factorial(number):
''' This function calculates the factorial of a number '''
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)

0 comments on commit bd269f2

Please sign in to comment.