6. is_prime question


#1

Hello guys. What is wrong with my code?

Thank you.


#2

Figured it out :slightly_smiling:


#6

for i in range(2,x) -- is not valid ,since it will give reminders zero when divided by itself
ex :

is_prime(7)
for i in range(2,7) -- 2-3-4-5-6-7

7%7 == 0 --- will satisfy the for condition and will return False while its should be true.

i think the correct range will be

for i in range(2,x-1):


#8


#9

Hi @projee, range(x, y) takes values starting from x, but goes only till y - 1 i.e. it doesn't include the y value. Hope it helps!

See on repl


#10

Thanks for the explanation