Program to check prime number in python

The following program shows how to check if a number is a prime number or not by taking a input from the user. Prime number is always greater than 1. The program is using for loop and the if- else statement.

# Taking an input number from the user

number = int(input("Enter a number of your choice:"))

# Prime numbers are greater than 1

if number > 1:

    # Check the divisibility by 'i' if it has any factor

    for i in range(2, number):

        if (number % i) == 0:

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

            print(i, "multiplied by", number // i, "will be", number)

            break
    else:

        print(number, "This number is a prime number")

# If number is less than or equal to 1

else:

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

Output 1 :

Output 2 :

Output 3 :

Output 4 :

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments