Skip to content

Commit a849dc6

Browse files
committed
factorial edited
1 parent 40a9a6e commit a849dc6

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

factorial.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
#finding factorial of a number using recursion by user input
2+
n=int(input("Enter a number: "))
13
def fact(n):
24
if (n==0 or n==1):
35
return 1
46
else:
57
return fact(n-1)*n
6-
7-
8-
9-
print(fact(6))
8+
print(f"Factorial of {n} is {fact(n)}")
9+
# Finding factorial of a number using loop by user input
10+
n=int(input("Enter a number to find its factorial: "))
11+
factorial = 1
12+
for i in range(1, n+1):
13+
factorial *= i
14+
print(f"The factorial of {n} is: {factorial}")

0 commit comments

Comments
 (0)