0
Write a function sumprimes(l) that takes as input a list of integers and retuns the sum of all the prime numbers in l.
3 ответов
+ 1
def sumprimes(n):
sum=0
if n == 1:
return False
if n == 2:
return True
for i in range(0,len(n)):
num=n[i]
if num>1:
pr=True
for j in range(2,int(num**0.5)+1):
if num%j == 0:
pr= False
break
if pr:
sum=sum+num
else:
sum=0
return sum
0
Stop with your flood about other web-site/app task... Try it by yourself, you will never learn nothing by this way :P
0
def sumprimes(n):
sum=0
if n == 1:
return False
if n == 2:
return True
for i in range(0,len(n)):
num=n[i]
if num>1:
pr=True
for j in range(2,int(num**0.5)+1):
if num%j == 0:
pr= False
break
if pr:
sum=sum+num
else:
sum=0
return sum