Python Program to check if a number is prime or not

Python Program to check if a number is prime or not

Python Program to check if a number is prime or not
Python Program to check if a number is prime or not

num = int(input("Enter a number: "))


flag = False


# prime numbers are greater than 1

if num > 1:

    # check for factors

    for i in range(2, num):

        if (num % i) == 0:

            # if factor is found, set flag to True

            flag = True

            # break out of loop

            break


if flag:

    print(num, "is not a prime number")

else:

    print(num, "is a prime number")

Load comments