I can't do this... Is_Prime


#1


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
        else:
            return True


#2

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


#3

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.


#4

Idon'tunderstandthat:(


#5

/ 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.


#6

Ohhh Okay thanks :slight_smile:


#7

def is_prime(x):

if x > 1:

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

print is_prime(9)


#8

Man stop finding all of my QA forum pages


#9

Lol
:slight_smile: .


#10

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


#11

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


#12

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