Checking if a number is prime in Python

PythonPrimes

Python Problem Overview


I have written the following code, which should check if the entered number is a prime number or not, but there is an issue I couldn't get through:

def main():
    n = input("Please enter a number:")
    is_prime(n)

def is_prime(a):
    x = True
    for i in (2, a):
            while x:
               if a%i == 0:
                   x = False
               else:
                   x = True


    if x:
        print("prime")
    else:
        print("not prime")

main()

If the entered number is not a prime number, it displays "not prime", as it is supposed to, but if the number is a prime number, it doesn't display anything. How can I fix this?

Python Solutions


Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsteveView Question on Stackoverflow