Input a number and check if the number is a prime or composite number Python Program

 

num = int(input("Enter any number : "))
if num > 1:
    for i in range(2, num):
        if (num % i) == 0:
            print(num, "is NOT a PRIME number, it is a COMPOSITE number")
            break
    else:
        print(num, "is a PRIME number")
elif num == 0 or 1:
    print(num, "is a neither Prime NOR Composite number")
else:
    print()

 

 

Output:

 

Enter any number : 5
(5, 'is a PRIME number')
>>>

 

Enter any number : 123
(123, 'is NOT a PRIME number, it is a COMPOSITE number')
>>>

 

 

 

 

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved