Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-alan-jose committed Mar 16, 2023
1 parent ae8d50c commit 8ef960b
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions Python Program for factorial of a number
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720.
"""
Factorial of a non-negative integer, is multiplication of
all integers smaller than or equal to n.
For example factorial of 6 is 6*5*4*3*2*1 which is 720.
"""

"""
Recursive:
# Python 3 program to find
# factorial of given number
Python3 program to find factorial of given number
"""
def factorial(n):

# single line to find factorial
return 1 if (n==1 or n==0) else n * factorial(n - 1);

# Driver Code
num = 5;
print("Factorial of",num,"is",
factorial((num))
print("Factorial of",num,"is", factorial((num)))

"""
Iterative:
# Python 3 program to find
# factorial of given number
Python 3 program to find factorial of given number.
"""
def factorial(n):
if n < 0:
return 0
Expand All @@ -29,5 +35,4 @@ def factorial(n):

# Driver Code
num = 5;
print("Factorial of",num,"is",
factorial(num))
print("Factorial of",num,"is", factorial(num))

0 comments on commit 8ef960b

Please sign in to comment.