Returns none instead of False



Your function fails on is_prime(0). It returns None when it should return False.

returns False

def is_prime(x):
    for n in range(2, x-1):
        if x/n==0:
            return False
            return True


When x is 0, how many iterations does your loop do? (Look at start and stop values before coming up with an answer, don't guess)

And, since your function always returns during an iteration, it will never do a second iteration. That loop isn't a loop.


Thanks jonathan I got through the question after a couple of more tries
Thanks for the help

בתאריך 26 בדצמ' 2016 10:14,‏ "Jonatan" כתב:


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