Answer to Question #310866 in Python for Fe 2

Question #310866

Sum of prime numbers from m to n




Input


5 11

1
Expert's answer
2022-03-14T13:05:02-0400
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        
    
# To take input from the user
n = int(input("Enter n: "))
m = int(input("Enter m: "))


sum = 0
while n <= m:
    if isPrime(n):
        sum += n;
    n = n + 1
    
print(sum)      

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
New on Blog
APPROVED BY CLIENTS