Find the percentage of prime numbers laying between 10and 34 to the total number of numbers
Answers
Answer:
thanks for free points
Answer:
print "Program to find the sum of prime numbers between 10 and 30."
print ""
print "Here is the list:"
def prime(n): # returns True if n is prime, False if not.
flag = True
for j in range(2,n+1):
if (n % j ==0 and j<>n): # n is composite (not prime).
flag = False
return flag
else:
if n ==j: # all possible divisors checked. Number,n is prime.
return flag
count = 0
scount = 0
for num in range(10,31):
if (prime(num)): # if flag is True...Its a prime!
count += 1
scount += num
print count,":",num," " ,
print ""
print "The sum of the",count,"primes between 10 & 30 is",scount
The program output:
Program to find the sum of prime numbers between 10 and 30.
Here is the list:
1 : 11 2 : 13 3 : 17 4 : 19 5 : 23 6 : 29
The sum of the 6 primes between 10 & 30 is 112
>>>
Good luck!