-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtutorial_24.py
47 lines (37 loc) · 837 Bytes
/
tutorial_24.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# basic syntax
'''
while True:
print('will loop forever')
while False:
print('will never loop')
init = True
while your_condition or init:
init = False
print('will loop at least once')
'''
# video example
num = ''
# loop until user enters a digit
init = True
while not num.isdigit() or init:
init = False
num = input('Check for prime of: ')
# convert string digit to integer
num = int(num)
# basic prime check and setup
if num <= 1:
print(num, 'is not prime.')
check_more = False
else:
divisor = num - 1
check_more = True
# more indepth check (examples of break and continue)
while check_more:
if divisor == 1:
print(num, 'is prime.')
break
if (num % divisor) == 0:
print(num, 'is not prime.')
check_more = False
continue
divisor -= 1