Please explain this code to me sir, I don't understand how it is written. What for instance does x - 1 do


def is_prime(x):
if x < 2:
return False
for n in range(2, x-1):
if x % n == 0:
return False
return True


well, we don’t want to include x in our loop. We want values lesser then x, so we need x - 1

however, range does not includes its stop value, so you don’t need minus one.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.