100以内素数之和
程序员文章站
2022-05-11 19:53:13
...
sum1 = 0
for num in range(2,100):
flag = 0;
for i in range(2,num//2+1):
if num%i == 0:
flag = 1;
break
if flag == 0:
print(num,end=',')
sum1+=num
print("素数之和为:",sum1)
Tip:
list(range(2,2))=[ ]空列表
所以 i=null—>num%i=null不等于0—>flag!=0