# Is_prime

#1

Oops, try again. Your function fails on is_prime(2). It returns None when it should return True.

to return true at the end

``````Replace this line with your code.
def is_prime(x):
if x < 2:
return False
elif x >=2:
for n in range(2,x-1):
if n % x == 0:
return False
else:
return True``````

#2

2. Work on code's logic again,

do reply if you solved it or not!
Hope it helps

#3

i have indented the code properly but i dnt wth the code logic am stuck pls help

#4

I give you my logic..(there are many ways to do this problem though)

1.First I will check if x == 2, if it is then return True

2.Then I will check if number x > 2 and will test these...

``````         1. If this number is divisible by range of number `range(2,x)`
2. If it is divisible by any number return False``````

3.last line?
I'm not telling you, Figure this out!

I hope it helps!

#5

thanks
i get it right

#7

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