Open in TheBrain

euler2 Even Fibonacci Total

<p>Jun 25, 2012 10:50 AM

&#160;

def euler2():

&#160;&#160;&#160;c=1

&#160;&#160;&#160;total=2

&#160;&#160;&#160;a=1

&#160;&#160;&#160;b=2

&#160;&#160;&#160;while c&#60;4000000:

&#160;&#160;&#160;&#160;&#160;&#160;&#160;c=a+b

&#160;&#160;&#160;&#160;&#160;&#160;&#160;a=b

&#160;&#160;&#160;&#160;&#160;&#160;&#160;b=c

&#160;&#160;&#160;&#160;&#160;&#160;&#160;if c%2==0:

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;total=total+c

&#160;&#160;&#160;&#160;&#160;&#160;&#160;if c&#60;100:

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;print a,b,c,total

&#160;&#160;&#160;print total

&#160;

comments on euler2(): &#160;&#160;&#160;note the : &#160;colon after the name of the function &#160;euler2

note the indents

note the colon after the conditions in the while loop and the if statement

note the == &#160;double = &#160;means the logical equal test.

note.. NO punctuation needed to terminate the function defintion nor level

of embedding.. it's all done by indentation (supplied automatically by the editor)</p>