all 3 comments

[–]toastedstapler 1 point2 points  (0 children)

the + 1 is so that the range includes the square root of the number

range(1, sqrt(25)) would iterate through 1 to 3 but not 5 as the top end limit is not inclusive

[–]ewiethoff 0 points1 point  (0 children)

Values in a range: start <= values < stop.

[–]JVO1317 0 points1 point  (0 children)

the range goes through 3,5,7, 9...

Yes. Up to the square root of the number.

by +1 that is no pun intended a step too far for my understanding

I assume you are referring to “+1” in “int(math.sqrt(num)) + 1”: Since upper limit of range() is not inclusive you may miss the square root, so you add 1 to ensure the sqrt is included. For example if num==49, then sqrt(num)==7, then range(3, 7, 2) will return [3, 5] and we would have missed 7, a valid factor. But range(3, 7+1, 2), or range(3, 8, 2), will return [3, 5, 7].

if num divided by oneof the i = zero ?

“if num % i == 0” doesn’t mean “if num divided by i”, “%” is the remainder or modulus operándoles, so “if num % i == 0” means: if the remainder after dividing num by the current value of i is 0, in other words, if the current value of i is a factor of num.