Passed
Pull Request — main (#159)
by
unknown
01:28
created

factorial   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 11
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A factorial() 0 7 2
1
# This Python Program finds the factorial of a number
2
3
def factorial(num):
4
    """This is a recursive function that calls
5
   itself to find the factorial of given number"""
6
    if num == 1:
7
        return num
8
    else:
9
        return num * factorial(num - 1)
10
11
12
# We will find the factorial of this number
13
num = int(input("Enter a Number: "))
14
15
# if input number is negative then return an error message
16
# elif the input number is 0 then display 1 as output
17
# else calculate the factorial by calling the user defined function
18
if num < 0:
19
    print("Factorial cannot be found for negative numbers")
20
elif num == 0:
21
    print("Factorial of 0 is 1")
22
else:
23
    print("Factorial of", num, "is: ", factorial(num))
24