Write a program that defines a function to determine whether input number n is prime or not. A positive whole number n > 2 is prime, if no number between 2 and √n (inclusive) evenly divides n. If n is not prime, the program should quit as soon as it finds a value that evenly divides n in python

Code

import math

def test_for_prime(n):
n = abs(n)
j = 2
stop=math.sqrt(n)
while j <= stop:
if n % j == 0:
return False
j += 1
return True

if __name__ == "__main__":
print("This program determines if a number you enter is prime or not.\n")
n_input = int(input("Please enter a number greater than 1: "))

result=test_for_prime(n_input)
if result:
print(n_input, "Is prime")
else:
print(n_input, "is Not prime")


Output

run this code and comment the output