일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 브렉시트
- terminal
- numpy
- 세계사
- Python
- 블록체인
- TFRecord
- Inference
- Perceptron
- 비트코인
- error
- TF
- TensorFlow
- img
- keras
- deeplearning
- itksnap
- 퍼셉트론
- loss
- pyqt
- Training
- opencv
- dtype
- qtdesigner
- cv2
- 유로화
- 세계대전
- 유가 급등
- 딥러닝
- DataSet
Archives
- Today
- Total
활연개랑
[python(파이썬) ] 자기 자신을 호출하는 재귀함수로 factorial(n) 구하기 본문
반응형
def factorial (n):
if n>0:
return n*factorial (n-1) # n과 n-1의 factorial을 구하기 위해 또 factorial함수가 실행되겠죠 ?
else:
return 1 # else일 경우는 n=0이 되는 경우인데 그렇게되면 factorial 값이 다 날아가기 때문에 return 1을 해줍니다.
F1= int(input('factorial을 구할 수를 입력해주세요>'))
print ('F1의 factorial>',factorial(F1))
F2= int(input('factorial을 구할 수를 입력해주세요>'))
print ('F2의 factorial>',factorial(F2))
F3= int(input('factorial을 구할 수를 입력해주세요>'))
print ('F3의 factorial>',factorial(F3))
==>
factorial을 구할 수를 입력해주세요>1
F1의 factorial> 1
factorial을 구할 수를 입력해주세요>5
F2의 factorial> 120
factorial을 구할 수를 입력해주세요>10
F3의 factorial> 3628800
'Python' 카테고리의 다른 글
[python(파이썬) ] 짝꿍/커플을 만드는 zip함수 (1) | 2021.07.08 |
---|---|
[python(파이썬) ] 값을 걸러내는 filter 함수 (0) | 2021.07.08 |
[python(파이썬) ] map 함수 ( 이해하기 쉽게 설명) (0) | 2021.07.08 |
[python(파이썬)] tikinter에서 keyboard event 동작하기 (키 누르면 이벤트 실행) 함수랑 결합 / -jupiter notebook (0) | 2021.07.04 |
[python(파이썬) ] 반복구간에서 객체가 현재 어디에 있는지 찾기 ( enumerate 함수) (0) | 2021.06.27 |