Sum of prime numbers from m to n in python
Dec 13, 2023 in Python 175 views

## 1 answer to this question.

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}")

## How to read numbers from file in Python?

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

## I have a file of type text and fields separated with 'tab' so how to get avroschema from input text file in python

i have textfile now i want to ...READ MORE

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

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

+1 vote

## 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

## how do i change string to a list?

suppose you have a string with a ...READ MORE

## how can i randomly select items from a list?

You can also use the random library's ...READ MORE

+1 vote

## how can i count the items in a list?

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