Skip to content

Instantly share code, notes, and snippets.

@ogilviemt
Created March 23, 2014 21:12
Show Gist options
  • Select an option

  • Save ogilviemt/9729925 to your computer and use it in GitHub Desktop.

Select an option

Save ogilviemt/9729925 to your computer and use it in GitHub Desktop.
Accept input and determine prime numbers
import string
def is_prime(n):
n = abs(int(n))
if n < 2:
return False
if n == 2:
return True
if not n & 1:
return False
for x in range(3, int(n**0.5)+1, 2):
if n % x == 0:
return False
return True
def check_true_false(q):
if q == False:
if y == "A":
print "%d is not a prime number." % z
else:
pass
else:
print "%d is a prime number." % z
x = int(input("Select range: 0 - "))
y = string.upper(raw_input("Show [a]ll or only [P]rimes? a/P: "))
z = 0
while z < len((range(x+1))):
check_true_false(is_prime(z))
z = z + 1
@ogilviemt
Copy link
Author

The ultimate goal is to create a number of tools to determine numerical theories from a set of numbers. I want to be able to pass those sets of numbers around and determine how they relate. For example, find a set of golden ratios and then determine if there is a pattern of prime numbers from their divisors, and so on. This is just one piece of code that will eventually become part of a larger program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment