Robotics & Artificial Intelligence
Write a function which returns if a number passed as an argument is a prime or composite number.
Python Functions
3 Likes
Answer
def prime_composite(n):
if n <= 1:
return "Neither Prime nor Composite"
count = 0
for i in range(1, n + 1):
if n % i == 0:
count = count + 1
if count == 2:
return "Prime Number"
else:
return "Composite Number"
num = int(input("Enter a number: "))
result = prime_composite(num)
print(result)Output
Enter a number: 7
Prime Number
Enter a number: 12
Composite Number
Answered By
3 Likes
Related Questions
Discuss the structure of a Python function with the help of an example.
Write a function which returns if a number passed as as argument is a perfect number or an Armstrong number.
Write a function which counts and displays the number of vowels, consonants, uppercase, and lowercase characters in a string entered as input.
Write a function which deletes all the negative values from a list passed as an argument.