Answer to Question #350879 in Python for Skvp

Question #350879

Given a list of integers, write a program to print the sum of all prime numbers in the list of integers.


Note: one is neither prime nor composite number


Using the pass statement

1
Expert's answer
2022-06-15T07:06:48-0400
entered_list = input("Enter a list of numbers separated by spaces: ").split()
num_list = list(map(int, entered_list))
prime_number = []
for i in num_list:
    for j in range(2, i):
        if i % j == 0:
            break
    else:
        prime_number.append(i)
for i in prime_number:
    if i == 1:
        prime_number.remove(i)
    else:
        pass
if len(prime_number) > 0:
    print(sum(prime_number))
else:
    print("There are no prime numbers in this list")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS