forked from PacktPublishing/AdvancedPythonProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2.py
More file actions
31 lines (22 loc) · 673 Bytes
/
example2.py
File metadata and controls
31 lines (22 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# ch3/example2.py
import _thread as thread
from math import sqrt
def is_prime(x):
if x < 2:
print('%i is not a prime number.' % x)
elif x == 2:
print('%i is a prime number.' % x)
elif x % 2 == 0:
print('%i is not a prime number.' % x)
else:
limit = int(sqrt(x)) + 1
for i in range(3, limit, 2):
if x % i == 0:
print('%i is not a prime number.' % x)
return
print('%i is a prime number.' % x)
my_input = [2, 193, 323, 1327, 433785907]
for x in my_input:
thread.start_new_thread(is_prime, (x, ))
a = input('Type something to quit: \n')
print('Finished.')