# prime_tester.py
# This program accepts a n value as input and determines whether
# or not it is prime.
# by: Scott Gordon
from math import sqrt
def is_prime(n):
"""Determines whether number (n) is prime or not"""
if n % 2 == 0 and n != 2:
return False
factor = 3
while factor <= sqrt(n):
if n % factor == 0:
return False
factor += 2
return True
def main():
print("Prime Number Tester\n")
n = int(input("Enter a number: "))
if is_prime(n):
print(f"{n} is prime.")
else:
print(f"{n} Is not prime.")
if __name__ == '__main__':
main()
Photo by Ryan Johns on Unsplash
Top comments (0)