문제(https://projecteuler.net/problem=2)
Each new term in the Fibonacci sequence is generated by adding the previous two terms.
By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million,
find the sum of the even-valued terms.
풀이
a = 1
b = 2
for i in range(0,10):
if i == 9:
print(a)
break
else:
print(a, end=',')
c = a+b # 1+2의 값을 c 에 넣는다.
a = b # 2의 값을 a 에
b = c # 3의 값을 b 에 넣고 다음 연산 2+3 을 실행하게끔
결과
1,2,3,5,8,13,21,34,55,89
'Language > Python' 카테고리의 다른 글
| AWS, Docker (0) | 2019.11.22 |
|---|---|
| 구글 트렌드(실시간 인기 급상승 검색어) selenium 삽질일기 (0) | 2019.09.23 |
| 점프 투 파이썬 - 프로그래밍 (0) | 2019.07.17 |
| 점프 투 파이썬 - 외장 함수 (0) | 2019.07.16 |
| 점프 투 파이썬 - 내장 함수 (0) | 2019.07.15 |
댓글