r/PythonLearning • • Aug 27 '25

Help

Post image

Where is the problem

17 Upvotes

22 comments sorted by

View all comments

3

u/timheiko Aug 27 '25

Here are my 2c:

  1. start the loop with 2, instead of 1 because n % 1 is always 0.

  2. indent the break inside the if-statement, i.e. four spaces to the right, so that the loop breaks only if the if’s condition evaluates to True.

  3. [a nitpick] use int(…) instead of eval(…) since eval(…) does more than you probably need in the program.

Enjoy your coding journey!

1

u/thw31416 Aug 31 '25

The eval is pretty scary there, executing user input as code. Someone putting in "import os; os.remove(...)" might be able to do quite some damage...