Kepala Pening wrote:
def sumEvenFibonacci( limit ):
a, b = 1, 1 # don't waste with a = 0
sum = 0
while b < limit:
if b%2 == 0: sum += b
a, b = b, a + b
return sum
print sumEvenFibonacci( 2000000 )
Every 3rd element in the Fibonacci series is an even number. So one
could economize slightly:
def sumEvenFibonacci(limit):
a, b = 1, 1 # don't waste with a = 0
sum = 0
while b < limit:
a, b = b, a + b
sum += b
a, b = b, a + b
a, b = b, a + b
return sum
--
Bob Gailer
919-636-4239 Chapel Hill, NC
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor