-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomated List Python program examples.py
More file actions
416 lines (295 loc) · 14.8 KB
/
Automated List Python program examples.py
File metadata and controls
416 lines (295 loc) · 14.8 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# Automated List Python program examples:
# Created by Joseph C. Richardson, GitHub.com
# Let's use the Python Idle that will help us create a list of values for us.
# You must type two or more values to start creating your list. Execute/run
# the Python program example below to view your created list of values,
# along with their variable name. Simply highlight all the blue text output,
# and then copy then paste that blue Python Idle text output back into your
# Python Idle editor. Next, execute/run the pasted Python code and watch
# it create a list of values, as if you had created the actual Python list and
# layout yourself.
m = 'make'
user_input_data_list_values = [ ]
print('''
Let me help you create a sorted list of values with Python.
Please type each data list value, one at a time, followed by
the "Enter" key. Type "make" to create and view your user
input data list values:''')
while True:
while True:
user_input_value = input(f'\nuser input data list value = ').lower().strip()
user_input_data_list_values.append(user_input_value)
user_input_data_list_values.sort()
if user_input_value == m:
user_input_data_list_values.remove(user_input_value)
break
if len(user_input_data_list_values) < 2:
print(f'\nYour user input data list must be over two values long.')
else:
print(
f'''\nuser_input_data_list_values = {user_input_data_list_values}
print('You have {len(user_input_data_list_values)} user input data list values:')
print(user_input_data_list_values)''')
break
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's use the Python Idle that will help us create a list of values for us.
# You must type two or more values to start creating your list. Execute/run
# the Python program example below to view your created list of values,
# along with their variable name. Simply highlight all the blue text output,
# and then copy then paste that blue Python Idle text output back into your
# Python Idle editor. Next, execute/run the pasted Python code and watch
# it create a list of values, as if you had created the actual Python list and
# layout yourself.
m = 'make'
user_input_data_list_values = [ ]
print('''
Let me help you create a sorted list of values with Python.
Please type each data list value, one at a time, followed by
the "Enter" key. Type "make" to create and view your user
input data list values:''')
while True:
while True:
user_input_value = input(f'\nuser input data list value = ').lower().strip()
user_input_data_list_values.append(user_input_value)
convert_list = set(user_input_data_list_values)
reconvert_list = list(convert_list)
reconvert_list.sort()
if user_input_value == m:
reconvert_list.remove(user_input_value)
break
if len(reconvert_list) < 2:
print(f'''\nYour user input data list must be over two values long.
No duplicate values allowed.''')
else:
print(
f'''\nuser_input_data_list_values = {reconvert_list}
print('You have {len(reconvert_list)} user input data list values:')
print(reconvert_list)''')
break
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's use the Python Idle that will help us create a list of values for us.
# You must type two or more values to start creating your list. However,
# this time we are forced type text letters only. Execute/run the Python
# program example below to view your created list of values, along with
# their variable name. Simply highlight all the blue text output, and then
# copy then paste that blue Python Idle text output back into your Python
# Idle editor. Next, execute/run the pasted Python code and watch it create
# a list of values, as if you had created the actual Python list and layout
# yourself.
m = 'make'
user_input_data_list_values = [ ]
text_error_message = '\ntext letters only please:'
print('''
Let me help you create a sorted list of values with Python.
Please type each data list value, one at a time, followed by
the "Enter" key. Type "make" to create and view your user
input data list values:''')
while True:
while True:
user_input_value = input(f'\nuser input data list value = ').lower().strip()
user_input_data_list_values.append(user_input_value)
user_input_data_list_values.sort()
if user_input_value < str([user_input_data_list_values]):
user_input_data_list_values.remove(user_input_value)
print(text_error_message)
elif user_input_value == m:
user_input_data_list_values.remove(user_input_value)
break
if len(user_input_data_list_values) < 2:
print(f'\nYour user input data list must be over two values long.')
else:
print(
f'''\nuser_input_data_list_values = {user_input_data_list_values}
print('You have {len(user_input_data_list_values)} user input data list values:')
print(user_input_data_list_values)''')
break
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's use the Python Idle that will help us create a list of values for us.
# You must type two or more values to start creating your list. However,
# this time we are forced type text numbers only. Execute/run the Python
# program example below to view your created list of values, along with
# their variable name. Simply highlight all the blue text output, and then
# copy then paste that blue Python Idle text output back into your Python
# Idle editor. Next, execute/run the pasted Python code and watch it create
# a list of values, as if you had created the actual Python list and layout
# yourself.
m = 9999
user_input_data_list_values = [ ]
text_error_message = '\ntext numbers only please:'
print('''
Let me help you create a sorted list of values with Python.
Please type each data list value, one at a time, followed by
the "Enter" key. Type "9999" to create and view your user
input data list values:''')
while True:
while True:
try:
user_input_value = int(input(f'\nuser input data list value = ').lower().strip())
user_input_data_list_values.append(user_input_value)
user_input_data_list_values.sort()
if user_input_value == m:
user_input_data_list_values.remove(user_input_value)
break
except ValueError:
print(text_error_message)
if len(user_input_data_list_values) < 2:
print(f'\nYour user input data list must be over two values long.')
else:
print(
f'''\nuser_input_data_list_values = {user_input_data_list_values}
print('You have {len(user_input_data_list_values)} user input data list values:')
print(user_input_data_list_values)''')
break
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's use the Python Idle that will help us create a list of values for us.
# You must type two or more values to start creating your list. However,
# this time we are forced type text numbers only. Execute/run the Python
# program example below to view your created list of values, along with
# their variable name. Simply highlight all the blue text output, and then
# copy then paste that blue Python Idle text output back into your Python
# Idle editor. Next, execute/run the pasted Python code and watch it create
# a list of values, as if you had created the actual Python list and layout
# yourself.
m = 9999
user_input_data_list_values = [ ]
text_error_message = '\ntext numbers only please:'
print('''
Let me help you create a sorted list of values with Python.
Please type each data list value, one at a time, followed by
the "Enter" key. Type "9999" to create and view your user
input data list values:''')
while True:
while True:
try:
user_input_value = int(input(f'\nuser input data list value = ').lower().strip())
user_input_data_list_values.append(user_input_value)
convert_list = set(user_input_data_list_values)
reconvert_list = list(convert_list)
reconvert_list.sort()
if user_input_value == m:
reconvert_list.remove(user_input_value)
break
except ValueError:
print(text_error_message)
if len(reconvert_list) < 2:
print(f'''\nYour user input data list must be over two values long.
No duplicate values allowed.''')
else:
print(
f'''\nuser_input_data_list_values = {reconvert_list}
print('You have {len(reconvert_list)} user input data list values:')
print(reconvert_list)''')
break
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Like always, I research when I want to learn something new, or new
# to me. Since the years I've played around with Python programming,
# I never ever explored list comprehension at all. This is like killing two
# birds with one stone's throw. List comprehension shortens for loops
# down when looping through a list, using a for loop right inside the
# list [ ] brackets.
# Create a list of values using list comprehension.
text_list_values = ['dog','cat','bird','fish','turtle']
text_list_values.sort()
values = [value for value in text_list_values]
print(values)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Create a list of values using list comprehension. Invoke the 'if' and
# 'else' statements that override all values, except the value 'bird'.
text_list_values = ['dog','cat','bird','fish','turtle']
text_list_values.sort()
values = [value if value == 'bird' else 'frog' for value in text_list_values]
print(values)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Create a list of values using list comprehension.
num_list_values = [6,2,5,1,3,4,8,7,10,9]
num_list_values.sort()
values = [value for value in num_list_values]
print(values)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Create a list of values using list comprehension. Invoke the 'if' and
# 'else' statements that override all values, except the value '9'.
num_list_values = [6,2,5,1,3,4,8,7,10,9]
num_list_values.sort()
values = [value if value == 9 else 100 for value in num_list_values]
print(values)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Create an integer number line using list comprehension.
values = [value for value in range(-10,+11)]
print(values)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's use the Python Idle that will help us create a multi dimensional
# integer list for us with this Python program example: Execute/run
# the Python program example below to view your created list
# of values, along with their variable name. Simply highlight all
# the blue text output, and then copy then paste that blue Python
# Idle text output back into your Python Idle editor. Next, execute/run
# the pasted Python code and watch it create a list of values, as
# if you had created the actual Python list and layout yourself.
auto_multi_dimensional_integer_list_creator = [ ]
print('auto_multi_dimensional_integer_list_creator = [')
for i in range(1,11):
auto_multi_dimensional_integer_list_creator.append(i)
print(f'{auto_multi_dimensional_integer_list_creator},')
print(']')
print('\nprint(auto_multi_dimensional_integer_list_creator[9][9])')
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Bonus Python program example: Make this Python program example
# ask the user their first name, last name and their age. If the user types
# incorrect data information, the program will prompt the user to type
# the correct data information allotted. Also if the user's age is less
# than nineteen years old, the program will give the user a sorry message
# that they are not old enough to drink yet.
user_first_name = '\nWhat is your first name please?: '
user_last_name = '\nWhat is your last name please?: '
user_age = 'How old are you?: '
age = 19
age_undefine = f'\nSorry! No such age. Please try again:'
old_enough = 'You are old enough to drink. Get SMASHED!'
not_old_enough = 'You are not old enough to drink yet.'
text_error_message = '\ntext letters only please:'
text_value_error_message = '\ntext numbers only please:'
text_length_message1 = '\nYour first name must be over two characters long.'
text_length_message2 = '\nYour first name must be under ten characters long.'
text_length_message3 = '\nYour last name must be over two characters long.'
text_length_message4 = '\nYour last name must be under ten characters long.'
while True:
user_input_first_name = input(user_first_name).lower().strip()
if user_input_first_name < str([user_input_first_name]):
print(text_error_message)
elif len(user_input_first_name) < 3:
print(text_length_message1)
elif len(user_input_first_name) > 10:
print(text_length_message2)
else:
break
while True:
user_input_last_name = input(user_last_name).lower().strip()
if user_input_last_name < str([user_input_last_name]):
print(text_error_message)
elif len(user_input_last_name) < 3:
print(text_length_message3)
elif len(user_input_last_name) > 10:
print(text_length_message4)
else:
break
while True:
try:
user_input_age = int(input(f'\nNice to meet you {user_input_first_name.title()} \
{user_input_last_name.title()}. {user_age}').strip())
if user_input_age == 18:
print(f'\nSorry {user_input_first_name.title()}. {not_old_enough} Come back \
in {age-user_input_age} year from now.')
break
elif user_input_age == 0:
print(age_undefine)
elif user_input_age < age:
print(f'\nSorry {user_input_first_name.title()}. {not_old_enough} Come back \
in {age-user_input_age} years from now.')
break
else:
print(f'\nCongrats {user_input_first_name.title()}. {old_enough}')
break
except ValueError:
print(text_value_error_message)
# I am almost a complete Walking Human Computer Science Research
# Laboratory Machine on Two Legs... 😁