본문 바로가기

programming

factorial

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def factorial(n):
    if not isinstance(n, intor n < 0:
        return None
 
    if n == 0:
        return 0
 
    if n == 1:
        return 1
 
    return n * factorial(n-1)
 
print(factorial(5)) #120
 
 
cs

 

파이썬 팩토리얼