Write a program to find the sum of all prime no. between 1 to 100
Answers
sum=0 # I'm taking a variable named 'sum' for getting the final value.
for a in range(2, 100): # This loop keeps the numbers from 2 to 99. So that we can use these numbers to find the prime numbers.
for i in range(2, a): # This loop will help us check wheater the given number coming from the above is prime or not.
if (a % i) == 0:
break
# Prime number is only divisible by 1 or itself only. If a number gives the remainder 0 when divided by any other number it'll not be a prime number.
# If the remainder comes to be 0 then the loop will exit go back to the first loop.
else: # But if the remainder is not 0 till the entire loop finishes then the number is a prime number.
sum+=a # Using this else condition the prime numbers can be taken. And the value of sum will change accordingly.
print("The sum of the prime numbers from 1 to 100 is {}.".format(sum)) # This will print the value of sum.