I have a question about a script i'm making. It asks the user to input an integer, then finds two prime numbers that sum up to the number, and displays what those two prime numbers are ( something like "54 = 5 + 49" ). I have most of the code working, but i'm not sure how to finish it up. So far, it finds the prime numbers that make up the number, but when it encounters a number that doesnt sum up to two prime numbers the program exits and goes back to the prompt with no message of any kind.
Primarily, what i'd like to do is create a check to see if the number the user entered is even. IF the number is even, the program then finds the two prime numbers that sum to that number. If it is NOT even, the program should exit with a "Number not even" message or similar.
Heres my code so far, can someone provide some input?
def main():
import math
def is_prime(p):
prime = True
if p%2 == 0:
prime = False
else:
for i in range(3, math.ceil(math.sqrt(p/2)), 2):
if p % i == 0:
prime = False
break
return prime
n = int(raw_input('Ener number to test: '))
for p in range(3, n/2, 2):
if is_prime(p) and is_prime(n-p):
print n, '= %d + %d' % (p, n-p)
print "Found two prime numbers that sum to",n
break
main()
Thanks!