Is_prime help?


It says it fails when using number 3; however it works just fine when using a python console on my local machine?

the same result as using the modulus that is in other threads

def is_prime(x):
    prime = True
    if x < 2:
        prime = False
    elif x == 2:
        prime = True
        for num in range(2, x):
            value = x / num
            if value - int(value) == 0:
                prime = False
    return prime


It works in Python 3, but not Python 2.

x / num

will be an integer.

float(x) / num

will be a float, whereby your method works fine.


Because of the extra logic, this method may prove to be slow on larger numbers.


showed some lag in the lab. A number that small should be instantaneous.


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