The following function returns a list of all prime numbers up to the figure supplied to it (n). Example:
import math
def prime(n):
answer = []
if n < 2:
return answer
for loop in range(2, n+1):
isPrime = True
upper = int(math.sqrt(loop))+1
for i in range(2, upper):
if loop % i == 0:
isPrime = False
if(isPrime):
answer = answer + [loop]
return answer
>>> prime(20)
[2, 3, 5, 7, 11, 13, 17, 19]
>>>
Using this function, write a program to show that each even number between any two user supplied integers, greater than 3, is the sum of two prime numbers (ensure that for each number you print the prime numbers which sum to it).
For example:
>>> question1()
Enter two numbers (greater than 3 and lowest first)5,30
Demonstrating that even numbers between 5 and 30 are the sum of two prime numbers
6 = 3 + 3
8 = 3 + 5
10 = 3 + 7
12 = 5 + 7
14 = 3 + 11
16 = 3 + 13
18 = 5 + 13
20 = 3 + 17
22 = 3 + 19
24 = 5 + 19
26 = 3 + 23
28 = 5 + 23