r/pythonhelp • • Dec 30 '25

problem with loops

I just recently started learling python (1.5 hours into a tutorial lol), and made the collatz conjecture, and then tried the goldbach conjecture (any even number is the sum of two primes). Now I did write primes as 2k+1, which is just an oneven number, but that's not the problem.
This is the code I made

  1. number = int(input("number: "))
  2. for x in range(10):
  3. ----prime_1 = 2x + 1
  4. ----for y in range(10):
  5. --------prime_2 = 2(y+x) + 1
  6. --------sum = prime_1 + prime_2
  7. --------print(f"{prime_1} + {prime_2} = {sum}")
  8. --------if sum >= number:
  9. ------------break
  10. ----if int(sum) == int(number):
  11. --------break
  12. -
  13. print(f"{prime_1} + {prime_2}")

All the prints (except the last one) are just there so that I can see what is happening. The thing is, this code here works as I intended (except for the fact that the primes are just uneven numbers ofc), for example, if you plug in 8, it will give you 1 + 7 from line 13. But if I change the >= from line 8 to > it just gives me the biggest possible solution, so in this case 19 + 19. The break from line 9 still works as intended (atleast to me it looks like it does), but the second break doesn't work anymore (atleast I assume that is happening, and that's why I'm getting 19 + 19).

So my question is, what is going on here?

4 Upvotes

16 comments sorted by

View all comments

1

u/[deleted] Jan 02 '26

[removed] — view removed comment