Created
March 23, 2014 21:12
-
-
Save ogilviemt/9729925 to your computer and use it in GitHub Desktop.
Accept input and determine prime numbers
This file contains hidden or 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 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.