Is_prime


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/6?curriculum_id=4f89dab3d788890003000096#

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

1.Indent your code properly
2. Work on code's logic again,

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


#3

i have indented the code properly but i dnt wth the code logic am stuck pls help
https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/6?curriculum_id=4f89dab3d788890003000096#


#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! :thinking: :slight_smile:

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.