Answers for "Write python code to find the sum of prime numbers from 2 to n where n is a positive integer entered by the user."

1

sum of prime numbers python

ending_range = int(input("Find sum of prime numbers upto : "))

total = 0

for num in range(2, ending_range + 1):

    i = 2
    
    for i in range(2, num):
        if (int(num % i) == 0):
            i = num
            break;

    #If the number is prime then add it.
    if i is not num:
        total += num

print("nSum of all prime numbers till", ending_range, ":", total)
Posted by: Guest on August-25-2021
0

python program to find n prime numbers

num = 10
for i in range(2,num+1):
    for j in range(2,i):
        if(i%j == 0):
            break
    else:
        print(i)
Posted by: Guest on March-10-2021

Code answers related to "Write python code to find the sum of prime numbers from 2 to n where n is a positive integer entered by the user."

Python Answers by Framework

Browse Popular Code Answers by Language