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

factorial.factorial()   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nop 1
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