-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff10fce
commit a713264
Showing
1 changed file
with
6 additions
and
5 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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
# Python program to find the factorial of a number provided by the user. | ||
|
||
def factorial(n): | ||
if n < 0: | ||
if n < 0: # factorial of number less than 0 is not possible | ||
return "Oops!Factorial Not Possible" | ||
elif n == 0: | ||
elif n == 0: # 0! = 1; when n=0 it returns 1 to the function which is calling it previously. | ||
return 1 | ||
else: | ||
return n*factorial(n-1) | ||
return n*factorial(n-1) | ||
#Recursive function. At every iteration "n" is getting reduced by 1 until the "n" is equal to 0. | ||
|
||
n = int(input()) | ||
print(factorial(n)) | ||
n = int(input("Enter a number: ")) # asks the user for input | ||
print(factorial(n)) # function call |