Since the question is less than 2000000, I used b < limit. However, to have limit = 2, perhaps I should do while b <= limit.
Thanks Alan for pointing it out. ----- Original Message ----- From: "Alan Gauld" <[EMAIL PROTECTED]> To: tutor@python.org Date: Thu, 31 Jul 2008 06:39:32 +0100 Subject: Re: [Tutor] Memory error - how to manage large data sets? > > "Kepala Pening" <[EMAIL PROTECTED]> 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 ) > > Does it work for limit = 2? > > Alan G. > > > > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor