Aug-08-2023, 10:08 PM
(This post was last modified: Aug-08-2023, 10:08 PM by deanhystad.)
Once you enter the loop it does not care if you change next_num, so your outer loop only tests if num + 1 is prime, and it doesn't do that correctly.
This is not a good test for prime:
Finding only one factor is enough to determine a number is not prime. You need to test all possible factors before you can say a number is prime.
This is not a good test for prime:
for i in range(2, next_num): if (next_num % i) == 0: next_num += 1 else: break print(f"The next prime number is {next_num}.")Let's say next_num = 9. You test if 9 is evenly divisible by 2. 9 % 2 == 1. It is not divisible by 2, so according to your program it is prime.
Finding only one factor is enough to determine a number is not prime. You need to test all possible factors before you can say a number is prime.