1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2013
Posts
1
Rep Power
0

#### Help on program!

hkhkj
2. Code:
# a program that will generate a list of prime numbers and find the sum of the primes in a certain range.

def list_prime_numbers_in_range(lo, hi):
'''
return a list of prime numbers in range(lo, hi)
doctests.  python -m doctest thisfile.py

>>> list_prime_numbers_in_range(40, 45)
[41, 43]
>>> sum(list_prime_numbers_in_range(-1000, 7))   # adding the numbers in the list
10
'''
primes = []    # useful
# for all the candidate primes in in range(max(lo, 2), hi)
# if the candidate is prime
# append the candidate to the list of primes
return primes

# next we need a function that tests a number for primality

#def is_prime(candidate):
'''
Boolean function that returns True if and only if the numeric argument is a prime number.
>>> [is_prime(maybe) for maybe in (60, 61, -99)]
[False, True, False]
'''
#
# for suitable trial divisors:
# if candidate mod (the trial divisor) equals zero:
return False  # not prime
return True  # passed the test, must be prime.

n = 10

result = list_prime_numbers_in_range(0,n+1)

print('primes less than or equal to {}: {}'.format(n, result))
print('sum of these: {}'.format(sum(result)))