Programming Examples
Find the sum of all the primes below a user-defined number.
Find the sum of
all the primes below a user-defined number.
Solutionn = int(input("Enter a number: "))
sum_prime = 0
for num in range(2, n):
is_prime = True
for i in range(2, num):
if num % i == 0:
is_prime = False
break
if is_prime:
sum_prime += num
print("Sum of all prime numbers below", n, "is:", sum_prime)
▶ RUN Output/ Explanation: