Goldbach conjecture - Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Goldbach conjecture - Python

Hi, I'm trying to code Golbach conjecture from sololearn coding challenges. It loops only one combination. Please help. def prime(numb): primeNumb = [2, ] i = 3 b = True z = 2 v = 0 c = 0 while i <= numb: while (z <= (i**0.5) and b == True): if i % z == 0: b = False z = z + 1 z = 2 if b == True: primeNumb.append(i) b = True i = i + 1 print(primeNumb) leng = int(len(primeNumb)) while True: x = primeNumb[v] y = primeNumb[c] if c >= (leng-1) and v >= (leng-1): break else: if x + y == numb: x = str(x) y = str(y) print(x+" + "+y) else: if c == (leng - 1): v = v + 1 c = 0 else: c = c + 1 while True: try: numb = int(input()) if numb % 2 == 0: prime(numb) break else: print("Even numbers only!") continue except ValueError: print("Uncorrect value")

25th Jul 2019, 11:33 AM
Dawid Uzarski
Dawid Uzarski - avatar
5 Answers
25th Jul 2019, 11:40 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Let me have a look
25th Jul 2019, 11:34 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Your code prints an infinite loop of the correct sum of primes.
25th Jul 2019, 11:36 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
0
One "else" too much in my code, thx :)
25th Jul 2019, 12:03 PM
Dawid Uzarski
Dawid Uzarski - avatar
0
Why it didn't work with extra "else" or "elif"? Can you explain?
25th Jul 2019, 12:06 PM
Dawid Uzarski
Dawid Uzarski - avatar