Sum of prime numbers in the input
Input
2 4 5 6 7 3 8
def isPrime(num):
# define a flag variable
flag = True
# prime numbers are greater than 1
if num > 1:
# check for factors
for i in range(2, num):
if (num % i) == 0:
# if factor is found, set flag to True
flag = False
# break out of loop
break
return flag
inp = list(map(int,input().split()))
sum = 0
for x in inp:
if isPrime(x):
sum += int(x)
print(sum)
Comments
Leave a comment