Bad instructions in "is_prime"


Instructions say to check for divisors up to x-1, that's silly, one need only check for divisors up to sqrt(x).

Add your code here, between the ```'s!


No, it should be x-1. Let say x = 11, you don't want to check 11. Because then you are loop is going to return False (no prime) while 11 is a prime number


Any number which is not prime has at least one factor less than or equal to its square root. To check for primeness one need only check that there are no "small" factors, i.e. that there are no factors less than or equal to the square root. This can considerably reduce the amount of work for the function.


Hold on, according to your title you are in practice makes perfect, is prime. There is nothing which involves square roots, could you provide me with the url of the exercise you are actually working on?


That's the right exercise, but I'm done with it now. The instructions work as it is, they're just very inefficient. In fact, the solution checker allowed me to use a loop similar to

while n ** 2 <= x:
    if x % n == 0:
        return False
    n += 1
return True

Maybe you can't use sqrt() without importing the math functions, but ** works.


well, if you are going to use things like sqrt, you are going outside the scope of the exercise, for which the instructions aren't written. So, it makes sense the instructions don't match


Again, it can be done without sqrt(), using n ** 2, as in the example. Anyway, minor issue.


Well, you get the point. Using till the power or sqrt is not within the parameters set by the exercise