Skip to content

Commit

Permalink
few comments are added
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayusreeyadavpadala committed Aug 10, 2023
1 parent ff10fce commit a713264
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions FIND FACTORIAL OF A NUMBER.py
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

0 comments on commit a713264

Please sign in to comment.