Python//10以内的素数2,3,5,7的和为17。要求计算得出任意正整数n以内的所有素数的和。

import math
n = int(raw_input("please enter number:"))

if n < 2:
    print "please enter a number greater than 2"
else:

    sum = 0

    for j in range(2,n+1):


        for i in range(2,j):
            if j % i == 0:
                break
        else:
            sum += j

    print sum

猜你喜欢

转载自blog.csdn.net/Marcuseve/article/details/82226369
今日推荐