r/PythonLearning • • Aug 27 '25

Help

Post image

Where is the problem

17 Upvotes

22 comments sorted by

View all comments

5

u/jamuzu5 Aug 27 '25

For the first loop, i =1.

First loop if statement:

Is n%1 == 0? Yes!

Next line prints "it is not a prime number"

Break and exit the loop.

Also, your last 3 lines aren't indented enough. Needs 1 more tab on each line.

4

u/calculus_is_fun Aug 27 '25

Just the break needs to be indented, the else block belongs to the for loop

1

u/thw31416 Aug 31 '25

Exactly. The else belonging to the if would be wrong, as a number is only not a prime when all numbers have been checked. So yes, this is best as a for...else in python with the else getting active whenever the loop didn't break prematurely. Quite a neat construct.