-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Prime Number Checker | ||
# Author: Powell A. Mims | ||
# This program checks if a number is prime or not | ||
|
||
def is_prime(num): | ||
if num == 4: # 4 / 2 = 2 --> range(2, 2) is empty. Skips | ||
return False; # for loop and causes erroneous true return. | ||
max = int(num / 2); | ||
for i in range(2, max): | ||
if num % i == 0: | ||
return False; | ||
return True; | ||
|
||
print("\nWelcome to the Prime Number Checker!\n"); | ||
number = input("What number should we check? "); | ||
|
||
if not number.isnumeric(): | ||
print("This program only works on integers."); | ||
exit(); | ||
|
||
number = int(number); | ||
if is_prime(number): | ||
message = ""; | ||
else: | ||
message = " not"; | ||
|
||
print(f"This number is{message} prime.\n"); |