// python projects

Goldbach Conjecture in Python

The Goldbach Conjecture is a famous unsolved problem in number theory that dates back to 1742. It was first proposed by the German mathematician Christian Goldbach, who wrote a letter to the famous mathematician Leonhard Euler in which he stated that 'every positive even integer greater than 2 can be expressed as the sum of two prime numbers.'

2021 2 min read pythonmath

The Goldbach Conjecture is a famous unsolved problem in number theory that dates back to 1742. It was first proposed by the German mathematician Christian Goldbach, who wrote a letter to the famous mathematician Leonhard Euler in which he stated that “every positive even integer greater than 2 can be expressed as the sum of two prime numbers.”.

# Program to check if a number is prime or not
num = 3
prime = []

# To take input from the user
# num = int(input("Enter a number: "))

while num != 100:
    if num > 1:
        # check for factors
        for i in range(2, num):
            if (num % i) == 0:
                num = num + 1
                break
        else:
            print(num, " is prime!")
            prime.append(num)
            num = num + 1
    else:
        num = num + 1


end = False

while end == False:
    # get first number in list
    first = prime[0]

    # print list of prime numbers
    print(prime)

    # Iterate through the list of prime numbers
    for x in prime:
        # sum of x and the first number in the list
        sum = x + first
        print(str(x), ' + ', str(first), ' = ', x + first)

        # if the sum is even, continue with the program
        if sum % 2 == 0:
            continue
        else:
            print("STOP")
            end = True
            break
    # get rid of first number in list
    prime.pop(0)

    # if the list of prime numbers is empty, exit while loop
    if not prime:
        end = True