Skip to content

Instantly share code, notes, and snippets.

@broschke
Last active March 12, 2019 15:50
Show Gist options
  • Save broschke/7d8e9cfe649a9dacfe88503aa19a98f7 to your computer and use it in GitHub Desktop.
Save broschke/7d8e9cfe649a9dacfe88503aa19a98f7 to your computer and use it in GitHub Desktop.
Python script that checks if a number is Prime
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