0

Python 2.75 で結果をリスト形式で出力する方法 (手動ではないコードを使用)。挿入した合計だけを求める代わりに、合計print iして数値を表示しました (11 個)。この非常に基本的な質問を手伝ってください。ありがとうございました。

##Even Fibonacci numbers 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...
##By considering the terms in the Fibonacci sequence whose values do not exceed
##four million, find the sum of the even-valued terms.
import fibo
sum = 0
a = fibo.fib2(4000000)
for i in a:
    if i%2==0:
        print i
        sum += i
print "the sum of these even Fibonacci numbers = "
print sum
###how to create list or tuple of the
##even_fib=[2, 8, 34, 144, 610, 2584, 10946, 46368, 196418, 832040, 3524578]
4

1 に答える 1