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

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')
>>>

 

 

 

 

Jitendra Singh
✔ Verified Educator

Jitendra Singh

Founder of CBSEPython.in

I help CBSE Class 9–12 students learn Python, Information Technology, Artificial Intelligence and Computer Science through easy notes, quizzes, MCQs and sample papers.

Read More About Me →

Leave a Comment

error: Content is protected !!