hello, I have a question
I want a program such that the sum of two primes number is an even integer greater than 2.
Steven Parker177,931 Points
Aren't all prime numbers greater than 2 odd?
So the sum of any two of them would be an even integer, right?
every even integer greater than 2 that can be written as the sum of two primes for example (8 = 5 + 3), (4=2 +2). i take one even integer greater than 2 such that i can sum two prime number two get that even number. I think first I need the program to recognize prime numbers and then when I put one even number I can give me two prime number or if there is not a prime number for the odd number it can give me a false.
the rule for the prime numbers is that can be divided by 1 and itself. and for even number can be divided by 2. (But it has to be greater than 2 as the problem says). Thanks, Lucas and Steven.
Lucas Garcia1,413 Points
I worked on it this morning and this is as far as I could get. I prompt user to enter an even integer and if it isn't even the program ends and ask user to please enter an even integer. However, if an even integer is entered than a for loop starts to get all the numbers less than the entered integer except 0 (so there is no division by zero error). Then we get rid of even numbers using modulo. Then we eliminate that odd numbers that aren't prime (like 9, 15, and 27) by using modulo with 3 and 5. Now you have all the prime numbers less than the even integer the user entered. Now all you have to do is find out which two prime numbers add up to the even integer. This should be a good start. Sorry I couldn't finish it!
#prompt user to input an integer integer = int(input("Please input an even integer: ")) #if input not even ask user to input even integer if (integer % 2) != 0: print("I am sorry. Please input an even integer: ") even_integer = integer #loop through all numbers less than even integer for i in range(even_integer): #only integers greater than 0 to prevent 0 division error while i > 0: non_zero_integers = i #get only odd integers if (non_zero_integers % 2) != 0: non_even_integers = non_zero_integers #get only prime numbers if((non_even_integers % 3) & (non_even_integers % 5)) != 0: prime_integers = non_even_integers print(prime_integers) break