Is_prime stuck


I can't figure it out what I'm missing. Pls. help I have overlooked.



if x <= 2:
    return True

why return True? 0, 1 and negative numbers are not prime numbers, but they are covered by this condition and thus will return True

Also, a function ends the moment a return keyword is reached, so for x=9, your function ends in the first run/iteration of the loop, that can't be right

a number is only a prime number if the whole loop finishes running successfully, so we only want to return True once the loop has finished running successfully, so we want to place return True outside the loop


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