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


#1

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


#2

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.


#3

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