-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added factorial implementation (recursive)
- Loading branch information
1 parent
305d1f9
commit bd269f2
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |