factorial

This commit is contained in:
Rohit Tanwar
2018-01-27 11:01:18 +05:30
parent 2bcb100b85
commit 94a4c53868
3 changed files with 35 additions and 1 deletions

View File

@ -6,10 +6,14 @@ Use recursion. If `num` is less than or equal to `1`, return `1`. Otherwise, ret
```python
def factorial(num):
if not ((num >= 0) & (num % 1 == 0)):
raise Exception(
f"Number( {num} ) can't be floating point or negative ")
return 1 if num == 0 else num * factorial(num - 1)
```
```
``` python
factorial(6) # 720
```