Open in TheBrain

Euler1 Total Divisible by 3 5

<p>Jun 25, 2012 07:55 PM

&#160;

Sean helps...

&#160;

def euler1 (): &#160;&#160;note colon &#160;then note indents &#160;and lack of punctuation

&#160;&#160;&#160;total=0

&#160;&#160;&#160;nlist=[] &#160;&#160;&#160;&#160;&#160;sets nlist to be the empty list

&#160;&#160;&#160;for n in range(3,1000): &#160;&#160;&#160;&#160;range gens all integers from 3 to 1000; also note the colon

&#160;&#160;&#160;&#160;&#160;&#160;&#160;if n%30 or n%50: &#160;&#160;&#160;n%3==0 &#160;&#160;is the test for divisibility by 3; &#160;that's n mod 3...

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;total=total+n

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if n&#60;50: &#160;&#160;&#160;&#160;&#160;&#160;&#160;note that colon after 50 in the condition; &#160;for the first 50 numbers

&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;nlist.append(n) &#160;&#160;&#160;&#160;&#160;append(n)

&#160;&#160;&#160;print nlist

&#160;&#160;&#160;print total</p>