Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialwalter fernandez
4,992 Pointshello, I have a question
I want a program such that the sum of two primes number is an even integer greater than 2.
4 Answers
Lucas Garcia
6,529 PointsI 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
Steven Parker
231,236 PointsAren't all prime numbers greater than 2 odd?
So the sum of any two of them would be an even integer, right?
walter fernandez
4,992 Pointsevery 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.
Steven Parker
231,236 PointsI'm still not sure I understand the objective.
walter fernandez
4,992 Pointsthe 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.
Steven Parker
231,236 PointsSteven Parker
231,236 PointsHow do you test your solution for correctness?