()
| 9 | import math, sys |
| 10 | |
| 11 | def main(): |
| 12 | print('Prime Numbers, by Al Sweigart al@inventwithpython.com') |
| 13 | print('Prime numbers are numbers that are only evenly divisible by') |
| 14 | print('one and themselves. They are used in a variety of practical') |
| 15 | print('applications, but cannot be predicted. They must be') |
| 16 | print('calculated one at a time.') |
| 17 | print() |
| 18 | while True: |
| 19 | print('Enter a number to start searching for primes from:') |
| 20 | print('(Try 0 or 1000000000000 (12 zeros) or another number.)') |
| 21 | response = input('> ') |
| 22 | if response.isdecimal(): |
| 23 | num = int(response) |
| 24 | break |
| 25 | |
| 26 | input('Press Ctrl-C at any time to quit. Press Enter to begin...') |
| 27 | |
| 28 | while True: |
| 29 | # Print out any prime numbers: |
| 30 | if isPrime(num): |
| 31 | print(str(num) + ', ', end='', flush=True) |
| 32 | num = num + 1 # Go to the next number. |
| 33 | |
| 34 | |
| 35 | def isPrime(number): |
no test coverage detected