Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Every even number greater than 2 can be written as the sum of two primes (possib

ID: 3891265 • Letter: E

Question

Every even number greater than 2 can be written as the sum of two primes (possibly the same one twice). For example:

4=2+2: 2isaprimenumber
6=3+3: 3isaprimenumber
8=3+5: 3and5arebothprimes
20=3+17: 3and17arebothprimes(7+13workstoo!) 124 = 11 + 113: 11 and 113 are both primes

In this problem, you are going to verify that the conjecture does indeed hold for 4 through 1000.

Your first mission is to create a function called is prime(). This function should take an integer as input, and return true if it has exactly two factors, and false otherwise.

Your next mission is to create a function called decompose(). This function should take a positive integer as input, and return a list: the list should either contain (any) two prime numbers that sum to the input, or an empty list if it is impossible to express a number as the sum of two primes (for example, many odd numbers, like 11, can’t be written in that way). For example, decompose(20) should return [3,17] (or [17,3], or [7, 13] – any of them is fine), while decompose(11) should return [].

This function should contain a call (or calls) to is prime()!.
Finally, verify that all the even integers between 4 and 1000 satisfy Goldbach’s conjecture, by printing out a list that looks

like:

4=2+2 6=3+3 8=3+5 10 = 3 + 7 ...

Again, if there are multiple possibilities for a given integer, any one is acceptable.

Explanation / Answer

Hello,

Here is the code as you mentioned in your question. If you need to add any other feature of edit any other thing you can absolutely do it. :)

def GBconjecture(Num):
    x, y = 0, 0
    result = 0
    if not Num % 2:
        ListOfPrime = LOP(Num)
        while result != Num:
            for i in range(len(ListOfPrime)):
                x = ListOfPrime[i]
                if result == Num: break
                for j in range(len(ListOfPrime)):
                    y = ListOfPrime[j]
                    result = x + y
                    print("Addition {} and {}.".format(x, y))
                    print("Final Result {}".format(result))
                    if result == Num: break
    return x, y

def PrimeOrNot(Num):
    if Num % 2:
        for num in range(3, int(math.sqrt(Num)) + 1, 2):
            if Num % num == 0:
               return False
        return True
    else:
        return False

def LOP(Num):
    ListOfPrime = []
    for x in range(2, Num + 1):
            if PrimeOrNot(x):
                ListOfPrime.append(x)
    return ListOfPrime

def main():
    while True:
        usr_in = eval(input("Enter +ve Number greater than 1: "))
        if usr_in > 1: break
        else:
            print("Do enter a Valid Number.")

    ListOfPrime = GBconjecture(usr_in)
    print(ListOfPrime)

Hope, I have solved you problem. Thank you :) Have a pleasant day!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote