Python Program to Check Prime Number

Python Program to Check Prime Number


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

# define a flag variable
flag = False

if num > 1:

    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

# check if flag is True
if flag:
    print(num, "is not a prime number")
else:
    print(num, "is a prime number")