"""
Takes a positive integer as input and prints all divisors of n in the following way:
- If the divisor is 1, print "Neither: 1"
- If the divisor is prime, print "Prime: " followed by the divisor
- If the divisor is composite, print "Composite: " followed by the divisor
"""
def classify_divisors(n):
if (n > 1):
for i in range(1, n + 1):
if (n % i) == 0:
print("Composite: ", i)
if (i == 1):
print("Neither: ", i)
else:
print("Prime: ", i)
classify_divisors(12)
"""
The results I'm getting are :
Composite: 1
Neither: 1
Composite: 2
Composite: 3
Composite: 4
Composite: 6
Composite: 12
Prime: 12
"""
Tags:
这是:
相关问题 更多 >
编程相关推荐