Last active
March 12, 2019 15:50
-
-
Save broschke/7d8e9cfe649a9dacfe88503aa19a98f7 to your computer and use it in GitHub Desktop.
Python script that checks if a number is Prime
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
import math | |
user_num = raw_input("Enter a number: ") | |
num = int(user_num) | |
limit = int(math.sqrt(num)) | |
result_list = [] | |
for i in range(2,limit+1): | |
prime_test = num % i | |
result_list.append(prime_test) | |
if all(i > 0 for i in result_list) == True: | |
print num, "is a prime number" | |
else: | |
print num, "is not a prime number" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment