Composite Number in Python

Problem Statement:

The problem is to check if a number is a composite number in python. Composite numbers are numbers that are divisible by other numbers other than 1 and the number itself. Or, the number of factors of a number is greater than 2. For example, 4 is divisible by 1, 2, and 4 which is more than 2 and is a composite number. But, 3 is divisible only by 1 and 3 itself and hence is not a composite number.

Code for Composite Number in Python:

number = int(input("Enter your number: "))
n = 0

for i in range(1, number+1):
    if number % i == 0:
        n += 1

if n > 2:
    print("The number is composite")
    print("Sorry, your number is prime")



Also Read:


Author: Ankur Gajurel

I am Ankur from Nepal trying to learn different aspects of Information Technology and Physics. I like building websites and minor projects with Python.