import math
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def main():
while True:
n = int(input("Enter a number (or a negative number to exit): "))
if n < 0:
print("Exiting...")
break
if is_prime(n):
print(f"{n} is a prime number.")
else:
print(f"{n} is not a prime number.")
print()
if __name__ == "__main__":
main()
No comments:
Post a Comment