Im having a problem with an excercise in python. I should get a function is_prime(n): to define prime numbers. the program should give 3 types of output; 1. n is the multiplicative identity 2. n is not a prime number (n * d = n). 3. n is a prime.
im having a problem to get the 2. work right my output is: 12 is not a prime number.(2, '*', 6, '=', 12)
but should be
12 is not a prime number (2 * 6 = 12).
my code;
def is_prime(n):
msg1 = "is the multiplicative identity."
msg2 = "is not a prime number."
msg3 = "is a prime."
if n == 1:
return str(n) + msg1
for d in range(2, n):
msg4 = (d, "*", n // d, "=", n)
pass
if (n % d) == 0:
return str(n) + " " + msg2 + str(msg4)
else:
return str(n) + " " + msg3
print(is_prime(12))