Question #292407

Write a program that tests if a number is prime or not. Input a number from the user. The output should be ‘True’ if the number is a prime, ‘False’ otherwise.


Expert's answer

def isPrime(x):
    x = int(x)
    for i in range(2, x):
        if x % i == 0:
            return False
    return x >= 2


print(isPrime(input("Enter a prime number: ")))
LATEST TUTORIALS
APPROVED BY CLIENTS