You cannot change the value of loop variable in python for loop. Therefore, the for loop you uploaded should be changed to when loop in Python. Alternatively, you need to change the conditional expression a little, such as i <= sqrt(number)
.
i = 3
while i*i<=number:
if ....
i+=2
from math import sqrt
for i in range(3, int(sqrt(number))+1):
if ....
© 2024 OneMinuteCode. All rights reserved.