Answer to Question #292407 in Python for kalpana T

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.


1
Expert's answer
2022-01-31T07:56:06-0500
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: ")))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS