# Python Program to find Composite Number

You are Here:

## What is Composite Number?

A positive integer that has at least one divisor other than 1 and itself.

Tips: It is recommended to use our online Composite Numbers calculator for better understanding.

## Examples

The following table provides few examples of composite numbers.

NumberDivisorResult
131, 13Not a Composite Number
151, 3, 5, 15Composite Number
471, 47Not a Composite Number

## Using for loop

In the following example, we will check whether the number 12 is a Composite number or not using for loop.

### Example

Python Compiler
num = 12; count = 0; for i in range(1, num+1): if(num % i == 0): count += 1; if(count > 2): print("%d is a composite number" % num) else: print("%d is not a composite number" % num)

### Output

12 is a composite number

## Using while loop

In the following example, we will check whether the number 12 is a Composite number or not using while loop.

### Example

Python Compiler
num = 12; count = 0; i = 1; while(num >= i): if(num % i == 0): count += 1 i += 1 if(count > 2): print("%d is a composite number" % num) else: print("%d is not a composite number" % num)

### Output

12 is a composite number

## Composite Numbers between the Given Range

In the following example, we will find all the Composite numbers between 1 and 10.

### Example

Python Compiler
start = 1; end = 10; count = 0; print("Composite Numbers between %d and %d: " % (start, end)); for start in range(start, end+1): for i in range(1, start+1): if(start % i == 0): count += 1; if(count > 2): print(start, end=" ") count = 0

### Output

Composite Numbers between 1 and 10: 4 6 8 9 10

## Check Whether the Given Number is Prime or Composite

In the following example, we will check whether the given number is a Prime number or Composite number.

### Example

Python Compiler
num = int(input("Enter a (int) number: ")); count = 0; for i in range(1, num+1): if(num % i == 0): count += 1; if(count > 2): print("%d is a composite number" % num) else: print("%d is a prime number" % num)

### Output

Enter a (int) number: 54 54 is a composite number

## Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on Python with examples for quick and easy learning.

We are working to cover every Single Concept in Python.