MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / main

Function main

src/gamesbyexample/primenumbers.py:11–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9import math, sys
10
11def 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
35def isPrime(number):

Callers 1

primenumbers.pyFile · 0.70

Calls 1

isPrimeFunction · 0.85

Tested by

no test coverage detected