# Program to check if the user input is a composite number or not in Python

[1474 views]

## What is a Composite Number?

A composite number is a positive integer number that is not prime number. In other words, it is a positive integer number which has at least one divisor other than 1 and itself. The composite numbers up to 20 are 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20.

For example:
Input: 10
Output: yes, its Composite (Because 10 has divisors other than 1 and itself, for ex, 2 or 5).

Input: 5
Output: no, its not Composite (Because 5 is a prime number, as it has no other divisors other than 1 and itself).

## Problem Statement:

### Write a program to check if the user input is a composite number or not in Python

#### Code:

def composite(n): if n <=1: return("Number less than or equal to 1!") else: for x in range(2,n): if n%x==0: return("composite") return("Non composite, it's a prime number") try: n=int(input()) print("Input:",n) print(composite(n)) except: print("Error!!")

## Algorithm Logic Test

Our Quiz prepared by Experts Helps you identify your knowledge in Algorithms. Everyone should atleast attempt this Quiz Once.

##### Algorithm Quiz

Only 5% Users were able to score above 75% in this Quiz. Can You Crack this?