首页 » Algorithm, Project Eular, Python » Project Eular #1(Python)
12

接触Python一年多了,但一直没有用它写过什么正经的东西。刚好这个暑假暂时没法回家,在学校也不是特别忙,就把之前觊觎已久的Project Eular翻出来,准备用Python扫一遍,就当作学习Python了。不过以我可怜的水平,不知道能坚持几道…

今天先扫一道超级水题,增强下信心吧……
Project Eular #1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.

sum = 0
for num in range(3,1000,3):
    sum = sum+num
for num in range(5,1000,5):
    sum = sum+num
for num in range(15,1000,15):
    sum = sum-num
print sum

, ,

发表评论