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
Write a program to input any 20 numbers (including positive and negative). The program displays the sum of all positive numbers and negative numbers separately.
Write a program to enter a number and display the sum of its digits.
Sample Input: 642
Output: 12 (6+4+2 = 12)
Write a program to input 10 different numbers. Display the greatest and the smallest numbers among them.
Write a program to input a number. Check and display whether it is a Niven Number or not. (A number is said to be Niven when it is divisible by the sum of its digits).
Sample Input: 126
Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.