I can't do this... Is_Prime


I don't know what to expect anymore.
Can somebody help me?

Much appreciated!

My code is down here

def is_prime(x):
    for num in n:
        if x / n = int:
            return False
            return True


Remember this... I can't code that well


try using the remainder symbol to determine if it should return true or false (ex. 4%2 = 0) Since you are trying find if x is prime, you should find the remainder with numbers from 2 till x-1. Use a range function for that.
Also any number less than 2 is going to return false so put an if statement before your for statement.




/ will produce the reminder of the division. Use % to return the integer value of a division.

4/3 = 1.13 while 4%3 = 1.

The conditional check for prime numbers is your syntax would be n%num == 0.

This must be valid for a range of num from 2 to n-1.


Ohhh Okay thanks :slight_smile:


def is_prime(x):

if x > 1:

    for n in range(2,x-1):
        print n
        print x
        if x % n == 0:
            return False
        return True
    return False

print is_prime(9)


Man stop finding all of my QA forum pages


:slight_smile: .


hahahahaha. dude just chill, it worked for me, so I am just sharing. It might be helpful for others.


Yea but giving away the code rather than helping the guy is against the rules (I think)


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