Sum of prime numbers from m to n in python

0 votes
Sum of prime numbers from m to n in python
Dec 13, 2023 in Python by Hoor
• 4,230 points
980 views

1 answer to this question.

0 votes
def is_prime(number):

    if number < 2:

        return False

    for i in range(2, int(number ** 0.5) + 1):

        if number % i == 0:

            return False

    return True

def Sum_of_Primes(m, n):

    prime_sum = 0

    for number in range(m, n + 1):

        if is_prime(number):

            prime_sum += number

    return prime_sum

# Define your range m to n

m = 10

n = 40

result = Sum_of_Primes(m, n)

print(f"The sum of prime numbers from {m} to {n} is: {result}")
answered Jan 5, 2024 by Ali

Related Questions In Python

0 votes
1 answer

How to read numbers from file in Python?

Assuming you don't have extraneous whitespace: with open('file') ...READ MORE

answered Apr 16, 2019 in Python by SDeb
• 13,300 points
7,536 views
0 votes
0 answers
0 votes
0 answers

How to print square of first 100 natural numbers using iterations in python?

Can you make a program with nested ...READ MORE

Jul 22, 2019 in Python by Waseem
• 4,540 points
1,038 views
+1 vote
0 answers

Sum the values of column matching and not matching from a .txt file and write output to a two different files using Python

Name                                                    value DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 15657 DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 156579 DR_CNDAOFSZAPZP_GPFS_VOL.2 156579 DR_CNDAOFSZAPZP_GPFS_VOL.3 ...READ MORE

Nov 20, 2019 in Python by Sagar
• 130 points
1,240 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,522 views
0 votes
1 answer
0 votes
1 answer

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

To find the sum of prime numbers ...READ MORE

answered Mar 1, 2024 in Python by Shubh Saxena
1,009 views
0 votes
1 answer

How to find index from raw and column in python?

You probably want to use np.ravel_multi_index: import numpy as ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 58,020 points
1,330 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