Programming Language/Python3.6
[python 파이썬] while문을 이용한 피보나치 수열(Fibonacci Sequence) 구현하기
yen31
2024. 4. 21. 02:58
반응형
피보나치 수열의 첫 50개 항을 차례대로 출력하는 코드
previous = 0 # 직전 항
current = 1 # 현재 항
i = 1
while i <= 50:
print(current)
temp = previous # previous를 임시 보관소 temp에 저장
previous = current
current = current + temp # temp에는 기존 previous 값이 저장돼 있음
i += 1
반응형