Is prime


def is_prime(x):
    if x==0 or x==1:
            return False
            print "not prime"
    elif x==2:
            return True
            print "prime"
        for n in (2,(x-1)):
            if result==0:    
                return False
                print "not prime"
                print "prime"
                return True

I don't see where i'm wrong...

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

Is_Prime returns noe

i know this is lazy, but i just explained the same thing two minutes ago here, please read it, if you then have any further questions, you can ask them in this topic


way If i return True outside my for loop, the result will not return True in any case...?


It finally works:

def is_prime(x):
        if x<2:
                return False
        if x==2:
                return True
        for n in range(2,x):
                print (x%n)
        print (result)
        for i in result:
                if i ==0:
                        print ("not Prime")
                        myBool= False
        if myBool==False:
                print (False)
                return False
                print (True)
                return True


Just a reminder. Anything after a return statement is not executed.


yes, but inside loop only i think. In my case, it works well


Not just a loop but anywhere in your program.


why did you change your code so much? No need

anyway, if you add a function call with a print statement:

print is_prime(11)

you should see True be printed


stetim94, i add those think in my code because i was supposing, would be more easy to store my results in variable outside the loop, and also use if condition (outside loop) to manage easily with "return" in both cases(if and else).
Surely it's possible to do shortly, but don't know how yet...


i was answering to many is_prime questions at once. A good challenge for later to optimize the code.