Respuesta :
Answer:
This function (along with the main)is written using python progrmming language.
The function is written using for loop;
This program does not make use comments (See explanation section for detailed line by line explanation)
def is_prime(num):
if num == 1:
print(str(num)+" is not prime")
else:
for i in range(2 , num):
if num % i == 0:
print(str(num)+" is not prime because it can b divided by "+str(i)+" and "+str(int(num/i))+" with no remainder")
break;
else:
print(str(num) + " is prime because only 1 and "+str(num)+" divide it with no remainder")
num = int(input("Number: "))
is_prime(num)
Explanation:
This line defines the function is_prime
def is_prime(num):
The italicize line checks if the user input is 1; If yes it prints 1 is not prime
if num == 1:
print(str(num)+" is not prime")
If the above conditional statement is not true (i.e. if user input is greater than 1), the following is executed
else:
The italicized checks if user input is primer (by using for loop iteration which starts from 2 and ends at the input number)
for i in range(2 , num):
if num % i == 0:
This line prints if the number is not a prime number and why it's not a prime number
print(str(num)+" is not prime because it can b divided by "+str(i)+" and "+str(int(num/i))+" with no remainder")
break;
If otherwise; i.e if user input is prime, the following italicized statements are executed
else:
print(str(num) + " is prime because only 1 and "+str(num)+" divide it with no remainder")
The function ends here
The main begins here
num = int(input("Number: ")) This line prompts user for input
is_prime(num) This line calls the defined function