-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwhile_bool.py
89 lines (52 loc) · 1.23 KB
/
while_bool.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# coding: utf-8
# # Boolean operators in while loops
# - Using while loop
# * with boolean comparison operators
# * <, >
# * <=, >=
# * ==, !=
#
# In[ ]:
count = 1
while count <= 5:
print(count)
count += 1
# In[ ]:
count = 5
while count >= 0:
print(count)
count -= 1
# In[ ]:
# another examples
count = 1
# loop 5 times
while count < 6:
print(count, "x", count, "=", count*count)
count +=1
# In[ ]:
# Using while with Boolean string tests
f_name = ""
while f_name.isalpha() == False:
f_name = input("Enter first name (letters with no spaces) : ")
print("\n" + f_name.title(), "has been entered as first name.")
# In[ ]:
number = ""
# number.isdigit() != True:
while number.isdigit() == False:
number = input("Enter the positive number : ")
print(number," is a positive number.")
# In[ ]:
# Long number using while with a boolean string
import pdb # importing debug module
int_num = input("Enter user input : ")
long_num = ""
while int_num.isdigit() == True:
long_num += str(int_num)
# pdb.set_trace()
int_num = input("Enter user input : ")
if int_num.lower().startswith('e'):
print()
break
print(long_num)
# In[ ]: