What is the algorithm to find the sum of prime numbers in the input in python

0 votes
What is the algorithm to find the sum of prime numbers in the input in python?
Feb 22 in Python by Prateek
• 180 points
863 views

1 answer to this question.

0 votes

To find the sum of prime numbers in a given list of numbers, follow this algorithm:

  1. Initialize a sum variable to 0 to keep track of the sum of prime numbers.
  2. For each number in the input list, perform the following steps:
    • Check if the number is greater than 1, because prime numbers are greater than 1.
    • Check if the number is prime by trying to divide it by all smaller numbers from 2 up to its square root. If it is divisible by any such number, it is not prime.
      • Start a loop from 2 to the square root of the number.
      • If the current number is divisible by any of these numbers, it's not a prime number. Break the loop and consider the next number in the list.
    • If the number is prime (i.e., it passes the above check), add it to the sum.
  3. After checking all numbers, return or output the sum of the prime numbers.
answered Mar 1 by Shubh Saxena

Related Questions In Python

0 votes
1 answer

What is the procedure to find the exact path of python installation in Windows?

This is a very simple thing to ...READ MORE

answered Aug 26, 2019 in Python by Neel
• 3,020 points
769 views
0 votes
1 answer

What is the logic to check if a number is prime or not in python?

n = int (input ('ENTER NUMBER TO ...READ MORE

answered Jul 16, 2020 in Python by amrut
• 240 points
1,083 views
0 votes
1 answer

What is the Python logic to count the number of capital letters in a file?

Hi, You can use this piece of code, ...READ MORE

answered Jun 26, 2020 in Python by Roshni
• 10,480 points
2,176 views
0 votes
1 answer

Sum of prime numbers from m to n in python

def is_prime(number):     if number < 2:         return False     for i ...READ MORE

answered Jan 5 in Python by Ali
864 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,464 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,122 views
0 votes
2 answers

what is the procedure to the version of python in my computer?

Execute the following command on your terminal: python ...READ MORE

answered Mar 20, 2019 in Python by Alia
939 views
0 votes
1 answer

Is it possible to find the source code of built-in functions of Python?

Since Python is open source you can ...READ MORE

answered Jul 17, 2019 in Python by Neel
• 3,020 points
4,794 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP