KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Write a Python code to check and display whether a number input by the user is a composite number or not.

[A number is said to composite, if it has one or more factors excluding 1 and the number itself. For example: 4, 6, 8, 9, ……………]

Python Control Flow

1 Like

Answer

c = 0
n = int(input("Enter a number: "))
for a in range(1, n+1):
    if n % a == 0:
        c = c + 1

if c > 2:
    print(n, "is a composite number")
else:
    print(n, "is not a composite number")

Output

Enter a number: 9
9 is a composite number

Enter a number: 13
13 is not a composite number

Answered By

2 Likes


Related Questions