Posted: Wed May 11, 2016 9:26 pm Post subject: Goldbach conjecture (Python 3)
Pretty self explanatory. I'm looking to program Goldbach's Conjecture in python but I need a bit of help. I have a fair amount of the code written already but I need a bit of help with my testGoldbach function.
code:
def nextNumber():
n = int(input("Please enter 0 or an even integer above 2: "))
while n < 0 and n <= 2 or n % 2 != 0: #Test to see if the input is valid
n = int(input("Please enter 0 or an even integer above 2: ")) #If the input is invalid, program prompts the user for another input, and will continue doing so until a valid input is supplied
return n
#def testGoldbach(n):
def isPrime(n):
if n < 2:
return False
for i in range(2,n):
if n % i == 0:
return False
return True
#def primeAfter(n):
Posted: Fri May 13, 2016 9:37 pm Post subject: Re: Goldbach conjecture (Python 3)
What is giving you trouble? Are you unsure of how to check if Goldbach's conjecture holds for a number, or is it something more specific?
For the former, think about how you might check it with pen and paper. Say I give you the number 124, how do you check if it is the sum of two odd primes? (seriously, grab a piece of paper and try it)
Try to figure out how you can use your approach to check other numbers. Then try to implement it.