Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6bc9c84

Browse filesBrowse files
MANYAJAIN195abranhe
authored andcommitted
add factorial program
1 parent 756e04c commit 6bc9c84
Copy full SHA for 6bc9c84

File tree

Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-0
lines changed

‎math/factorial.py

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''
2+
To find factorial of a number
3+
'''
4+
def factorial(num): #recursive function
5+
if num==1 or num==0:
6+
return 1
7+
else:
8+
return factorial(num-1)*num #function calling itself
9+
10+
num=int(input("Enter the number to find factorial:"))
11+
'''
12+
To check whether the number inputted is positive or not
13+
'''
14+
while num<0:
15+
print("INVALID INPUT !")
16+
num=int(input("Enter the number to find factorial:"))
17+
'''
18+
function calling
19+
'''
20+
x=factorial(num)
21+
print("Factorial of ",num," is ",x)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.