| Total Complexity | 2 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |