-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMental Metal Python Programming Examples.py
More file actions
700 lines (509 loc) · 23.3 KB
/
Mental Metal Python Programming Examples.py
File metadata and controls
700 lines (509 loc) · 23.3 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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# Here is some MENTAL METAL PYTHON 'DEATH METAL' PROGRAMMING EXAMPLES
# to play with. I say no more...
# Note: not recommended for beginners. But why not?!
# HIGHLIGHT AND COPY CODE, THEN PASTE INTO YOUR PREFERABLE PYTHON APP/IDLE
# Just discover and learn from these Python programming examples below.
# If you aren't sure what is happening. DO SOME HOMEWORK and figure
# these all out for yourself over the internet, such as YouTube is a GREAT
# START! That's the only place to start. I DID JUST THAT! I'm no hypocrite
# when it comes to this type of learning style; it's there. USE IT! I DO!! As a
# self taught Python programmer. I had to use VR teachers to teach me
# EVERYTHING I KNOW about Python in general. I'm as Human as You. I'm
# No one, nor am I BETTER THAN YOU! I had to learn all this Python stuff
# from VR teachers, mostly them. They are all on my channel, of those I
# recommend to others, who seek what I love to do. You can do it too...
# Just go and get it is all you have to do, and trust yourself and take the
# time to learn this kind of programming thing. Who knows? You might LOVE
# IT!
'''
Create three different integer sets that will combine/unionize all three sets into one
single set. Convert the single set into a list, using the list() function. Next, view the
contents of the list, along with the slice() function to set the range of list content
values to display on the screen.
Type and execute/run this Python program example below.
'''
# To reduce lines of code, create packed variables and their
# packed values.
x,y,z=(
{1,2,3,4,9,6,7,8,5,9,10},
{11,12,13,14,15,16,17},
{18,19,20,21,22,23,24})
a=slice(24) # slice the set with the slice() function
# To reduce lines of code, create packed variables and their
# packed values.
length1,length2,length3=len(x),len(y),len(z)
unionize=x.union(y,z) # unionize x to y and z with the value v.union() function
convert=list(unionize) # cast the set to a list with the list() function
answer=length1,length2,length3
# Add the total values between length1, length2 and length3 with the sum()
# function.
total_sum=sum(answer) # add all three values of answer together with the sum() function
# View the contents of x, y and z in their combined, converted sets to a list.
print('View the value contents of the unionized list to check it:\n\n'+str(convert[a]))
# Create a variable called sentence_loop, along with all its values.
sentence_loop=(
f'\nThe length of (x) = {length1}',f'The length of (y) = {length2}',
f'The length of (z) = {length3}',f'\nThe total lengths of x+y+z = {total_sum}')
# Create a for loop that will loop through the sentence_loop variable, using a
# single print() function. The for loop will iterate until all the values are cycled
# through the sentence_loop variable.
for i in sentence_loop:print(i)
x={1,2,3,4,9,6,7,8,5,9}
y={10,11,15,13,14,12,16,17,18,19,19}
z={20,21,22,23,27,25,26,24,28,29,22}
unionize=x.union(y).union(z)
convert=list(unionize)
a=slice(20)
print(convert[a])
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
x={1,2,3,4,9,6,7,8,5,9}
y={10,11,15,13,14,12,16,17,18,19,19}
z={20,21,22,23,27,25,26,24,28,29,22}
unionize=x.union(y,z)
convert=list(unionize)
a=slice(20)
print(convert[a])
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
a=list()
for i in range(10):
a.append(i)
b=set()
for i in range(10):
b.add(i)
print(a)
print(b)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
nums1={1,1,2,3,4,5,6}
nums2={1,2,2,3,4}
print(nums1 | nums2) # Union
print(nums1.union(nums2)) # Union
nums1={1,1,2,3,4,5,6}
nums2={1,2,2,3,4}
print(nums1 & nums2) # Intersection
print(nums1.intersection(nums2)) # Intersection
nums1={1,1,2,3,4,5,6}
nums2={1,2,2,3,4}
print(nums1 - nums2) # Difference
print(nums1.difference(nums2)) # Difference
nums1={1,1,2,3,4,5,6}
nums2={1,2,2,3,4}
print(nums1.symmetric_difference(nums2)) # Symmetric Difference
print(nums1 ^ nums2) # Symmetric Difference
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
nums1={0,1,2,3,1,3,4,10,5,6,6,7,8,9,10,23}
nums2={1,2,7,1,3,4,10,5,6,6,7,8,9,10,11,22}
print(nums1 | nums2) # Union
print(nums1 & nums2) # Intersection
print(nums1 - nums2) # Difference
print(nums1 ^ nums2) # Symmetric Difference
nums1=[1,2,3,1,3,4,10,5,6,6,7,8,9,10]
nums2=[1,2,3,1,3,4,10,5,6,6,7,8,9,10]
uniques1=set(nums1)
uniques2=set(nums2)
print(uniques1 | uniques2)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''
Did you know you can create variables for some of these Python
commands/functions? This will give us much more opportunities
to use variables as Python code in a for loop that loops through
a list of values, which are actual Python commands/functions.
You can create two or more Python commands/functions with
just one for loop alone. Let's explore what these variables can
do for us, using actual Python code itself.
'''
absolute_num = abs
add_nums = sum
ascii_character = ascii
ascii_character_num = ord
ascii_character_value = chr
binary_base_2 = bin
character_string = str
convert_to_list = list
convert_to_set = set
convert_to_tuple = tuple
dictionary = dict
float_num = float
George_Boole = bool
hexadecimal_base_16 = hex
index_error = IndexError
integer_num = int
maximum_num = max
memory_error = MemoryError
minimum_num = min
redundant_code = exec
round_num = round
super_function = super
text_input = input
text_print = print
value_error = ValueError
value_length = len
you_quitter = quit
must_exit = exit
# Let's try a simple print() command/function and see what this does
# We will also create a variable to be a text placeholder, so we don't
# have to keep rewriting text sentences over and over again.
text = "This was Python's print() command/function."
# this:
print("This was Python's print() command/function.")
# or this:
text_print(text) # use variables instead if you like
# Let's try a few more to get the hange of things. Let's add some numbers
# together with the sum() command/function, we renamed to 'add_nums'
# using a variable to store the actual sum() command/function. We also
# need to create a variable we'll call nums, so we can store a default tuple
# of numbers without any parenthesese, ie: (1,2,3,4,5,6,7,8,9)
nums = 1,2,3,4,5,6,7,8,9 # this is a tuple by default, without parentheses ' () '
# this:
print(sum(nums))
# or this:
text_print(add_nums(nums))
# Let's try a simple input() command/function and see what this does We will
# create a variable to be a text placeholder, so we don't have to keep rewriting
# text sentences over and over again. We also have to create an 'user_input'
# variable so the user can type into it.
input_text = "This was Python's input() command/function."
# this:
user_input = input("This was Python's input() command/function.")
# or this:
user_input = text_input(input_text)
# Let's use a for loop to loop through a tuple of variables, which are actual Python
# commands/functions. Let's creat our tuple called loop.
loop = integer_num,binary_base_2,hexadecimal_base_16
for i in loop:
text_print(f'{i(255)}. You only need one print statement with a list of variables.')
1
1
COMPUTER SCIENCE & PYTHON PROGRAMMING EXAMPLES:
COMPUTER SCIENCE & PYTHON PROGRAMMING EXAMPLES:
2 weeks ago (edited)
# Here is some MENTAL METAL PYTHON 'DEATH METAL' PROGRAMMING EXAMPLES
# to play with. I say no more...
# Note: not recommended for beginners. But why not?!
# HIGHLIGHT AND COPY CODE, THEN PASTE INTO YOUR PREFERABLE PYTHON APP/IDLE
# Just discover and learn from these Python programming examples below.
# If you aren't sure what is happening. DO SOME HOMEWORK and figure
# these all out for yourself over the internet, such as YouTube is a GREAT
# START! That's the only place to start. I DID JUST THAT! I'm no hypocrite
# when it comes to this type of learning style; it's there. USE IT! I DO!! As a
# self taught Python programmer. I had to use VR teachers to teach me
# EVERYTHING I KNOW about Python in general. I'm as Human as You. I'm
# No one, nor am I BETTER THAN YOU! I had to learn all this Python stuff
# from VR teachers, mostly them. They are all on my channel, of those I
# recommend to others, who seek what I love to do. You can do it too...
# Just go and get it is all you have to do, and trust yourself and take the
# time to learn this kind of programming thing. Who knows? You might LOVE
# IT!
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
poem = ('''‘Knowledge’
is a free invention of the heart and of the mind itself!
The only textbooks needed, are the heart and the mind.
The only exam to be written is the key to ponder into wonder.
For the heart and the mind hold the key to the greatest diploma of all,
the dream’s creation of our imagination.
For the heart and the mind are thus, the greatest teachers of us…
Believe in yourself! For you are their greatest student.'''[::-1],
'''.tneduts tsetaerg rieht era uoy roF !flesruoy ni eveileB
…su fo srehcaet tsetaerg eht ,suht era dnim eht dna traeh eht roF
.noitanigami ruo fo noitaerc s’maerd eht
,lla fo amolpid tsetaerg eht ot yek eht dloh dnim eht dna traeh eht roF
.rednow otni rednop ot yek eht si nettirw eb ot maxe ylno ehT
.dnim eht dna traeh eht era ,dedeen skoobtxet ylno ehT
!flesti dnim eht fo dna traeh eht fo noitnevni eerf a si
’egdelwonK‘'''[::-1])
print(poem[1])
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
for i in range(256):print(bin(i),hex(i),oct(i),i)
for i in range(256):print(f'{i:b} {i:x} {i:o} {i:d}')
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
nums = [i for i in range(1,11)];print(nums)
nums = [i+2 for i in range(1,11)];print(nums)
nums = [i-2 for i in range(1,11)];print(nums)
nums = [i*i for i in range(1,11)];print(nums)
nums = [i/2 for i in range(1,11)];print(nums)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
nums = [1,2,3,4,5,6,7,8,9,10]
num = [i if i>=5 else False for i in nums]
print(num)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
cubed = lambda x,y:x+y**3
print(cubed(10,10)) # 10*10*10 = 10 + 1000 = 1010
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
cubed = lambda x,y:x**3+y
print(cubed(10,10)) # 10*10*10 = 1000 + 10 = 1010
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
full_name = lambda \
first_name,middle_name,last_name:\
first_name+' '+middle_name+' '+last_name
print(full_name('First','Middle','Last'))
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
auto_multi_dimensional_list = []
for i in range(1,11):
auto_multi_dimensional_list.append(i)
print(auto_multi_dimensional_list)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Almost six years later, and I'm still learning how to master
# Python. I'm always trying new ideas through others so I can
# learn what Python is truly all about.
# Use the enumerate() function to loop through a list, using
# only two lines of code; one for the for-index enumerate()
# function and the other for the 'print' statement.
name_list=['John','Bob','Rob','Tom']
# Here is a simple for-loop that will loop through the name_list
# values starting with index 0, followed by index 1 and then
# index 2, and finally index 3.
for index in name_list:
print(index)
# The for-loop example above is fine, but it has its limitations
# when it comes to multi indexing through a tuple or list alike.
# With the enumerate() function, such things are possible.
# Try these enumerate() function Python program examples
# below and see what happens when you experiment with them.
for index,name in enumerate(name_list):
print(index)
for index,name in enumerate(name_list):
print(name)
for index,name in enumerate(name_list):
print(index,name)
for index,name in enumerate(name_list,start=1):
print(index,name)
name=['John','Bob','Rob','Tom']
pet=['Dog','Cat','Bird','Fish']
computer=['Desktop','Laptop','Cellphone','Notebook']
# Note: the zip() function only goes to the shortest length
# in a multi list. However, you can simply keep them the
# same size such as the list examples above, which shows
# three lists called name, pet and computer. Each list has
# four values in them. This way, every value gets called inside
# one, single 'print' statement. Try these different examples
# below. Note: you can rename the words 'index1, index2 and
# index3' to any names you wish. You can also rename the
# name variable if you like.
for index1,index2,index3 in zip(name,pet,computer):
print(index1)
for index1,index2,index3 in zip(name,pet,computer):
print(index2)
for index1,index2,index3 in zip(name,pet,computer):
print(index3)
for index1,index2,index3 in zip(name,pet,computer):
print(index1,index2,index3)
# Let's try the enumerate() function with a 2d-list.
my_2d_list=[
['John','Bob','Rob','Tom'],
['Desktop','Laptop','Cellphone','Notebook']]
for index,name in enumerate(my_2d_list):
print(index)
for index,name in enumerate(my_2d_list):
print(name[0])
for index,name in enumerate(my_2d_list):
print(index,name[0])
for index,name in enumerate(my_2d_list,start=1):
print(index,name[0])
# Let's try the zip() function with a 2d-list.
my_2d_list=[
['John','Bob','Rob','Tom'],
['Desktop','Laptop','Cellphone','Notebook']]
for index in zip(my_2d_list):
print(index[0][0])
for index in zip(my_2d_list):
print(index[0][0],index[0][1],index[0][2],index[0][3])
# Let's try some fun experiment examples with some of what
# we've learned so far about the enumerate() function. Let's
# create a program that uses a sentence for each value in the
# fun_list1, fun_list2 and fun_list3 lists. Let's use the f' format
# to make string concatenations much easier to create.
fun_list1=['John','Bob','Rob','Tom']
fun_list2=['Dog','Cat','Bird','Fish']
fun_list3=['Desktop','Laptop','Cellphone','Notebook']
for index,name in enumerate(fun_list1):
print(f"My name is {name}. I'm the value from the fun_list1, position {index}")
for index,name in enumerate(fun_list2):
print(f"I am a {name}. I'm the value from the fun_list2, position {index}")
for index,name in enumerate(fun_list3):
print(f"I am a {name}. I'm the value from the fun_list3, position {index}")
# These enumerate() function examples are great, but let's beef it up just a lot
# more with the zip() function, so we can create complex actions with all our
# fun_lists combined into complete, separate sentences, just simply using two
# lines of code. See what happens when you type and execute/run this Python
# program example below:
for list1,list2,list3 in zip(fun_list1,fun_list2,fun_list3):
print(f"My name is {list1} and I have a {list2} picture on my {list3} screen.")
# The zip() function is very useful, but it can only reach as far as its shortest
# list length. That means, if you have two, three or more lists, the shortest list
# out of the three or more lists values will be cut off from the rest if one or more
# lists have extra values inside them. To avoid this from occurring, make all your
# lists the same size in each of their values. take a look at the example below:
fun_list1=['John','Bob','Rob','Tom'] # four values
fun_list2=['Dog','Cat','Bird','Fish'] # four values
fun_list3=['Desktop','Laptop','Cellphone','Notebook'] # four values
# The zip() function is sometimes better than a simple for-loop or a simple
# enumerate() function, in that it uses less lines of code and it can also achieve
# a far better programming style approach over program code redundancy on
# the programmer's part.
# Let's try one more example to prove this to be true. let's create another
# fun_list, zip() function Python program example. Type and execute/run
# this Python program below and see what happens with the output.
fun_list1=['John','Bob','Rob','Tom']
fun_list2=['Dog','Cat','Bird','Fish']
fun_list3=['Desktop','Laptop','Cellphone','Notebook']
fun_list4=['loves my','hates my','found my','lost my']
fun_list5=['fed his',"didn't feed his",'plays with his',"doesn't play with his"]
for list1,list2,list3,list4,list5 in zip(fun_list1,fun_list2,fun_list3,fun_list4,fun_list5):
print(f'{list1} {list4} {list3} and {list5} {list2}.')
# Well, I think we pretty much learned what the enumerate() and zip() functions
# do. Now, it's practice, practice, practice and more practice, practice, practice...
'''
Create three different integer sets that will combine/unionize all three sets into one
single set. Convert the single set into a list, using the list() function. Next, view the
contents of the list, along with the slice() function to set the range of list content
values to display on the screen.
Type and execute/run this Python program example below.
'''
# To reduce lines of code, create packed variables and their
# packed values.
x,y,z=(
{1,2,3,4,9,6,7,8,5,9,10},
{11,12,13,14,15,16,17},
{18,19,20,21,22,23,24})
a=slice(24) # slice the set with the slice() function
# To reduce lines of code, create packed variables and their
# packed values.
length1,length2,length3=len(x),len(y),len(z)
unionize=x.union(y,z) # unionize x to y and z with the value v.union() function
convert=list(unionize) # cast the set to a list with the list() function
answer=length1,length2,length3
# Add the total values between length1, length2 and length3 with the sum()
# function.
total_sum=sum(answer) # add all three values of answer together with the sum() function
# View the contents of x, y and z in their combined, converted sets to a list.
print('View the value contents of the unionized list to check it:\n\n'+str(convert[a]))
# Create a variable called sentence_loop, along with all its values.
sentence_loop=(
f'\nThe length of (x) = {length1}',f'The length of (y) = {length2}',
f'The length of (z) = {length3}',f'\nThe total lengths of x+y+z = {total_sum}')
# Create a for loop that will loop through the sentence_loop variable, using a
# single print() function. The for loop will iterate until all the values are cycled
# through the sentence_loop variable.
for i in sentence_loop:print(i)
x={1,2,3,4,9,6,7,8,5,9}
y={10,11,15,13,14,12,16,17,18,19,19}
z={20,21,22,23,27,25,26,24,28,29,22}
unionize=x.union(y).union(z)
convert=list(unionize)
a=slice(20)
print(convert[a])
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
x={1,2,3,4,9,6,7,8,5,9}
y={10,11,15,13,14,12,16,17,18,19,19}
z={20,21,22,23,27,25,26,24,28,29,22}
unionize=x.union(y,z)
convert=list(unionize)
a=slice(20)
print(convert[a])
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
a=list()
for i in range(10):
a.append(i)
b=set()
for i in range(10):
b.add(i)
print(a)
print(b)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
nums1={1,1,2,3,4,5,6}
nums2={1,2,2,3,4}
print(nums1 | nums2) # Union
print(nums1.union(nums2)) # Union
nums1={1,1,2,3,4,5,6}
nums2={1,2,2,3,4}
print(nums1 & nums2) # Intersection
print(nums1.intersection(nums2)) # Intersection
nums1={1,1,2,3,4,5,6}
nums2={1,2,2,3,4}
print(nums1 - nums2) # Difference
print(nums1.difference(nums2)) # Difference
nums1={1,1,2,3,4,5,6}
nums2={1,2,2,3,4}
print(nums1.symmetric_difference(nums2)) # Symmetric Difference
print(nums1 ^ nums2) # Symmetric Difference
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
nums1={0,1,2,3,1,3,4,10,5,6,6,7,8,9,10,23}
nums2={1,2,7,1,3,4,10,5,6,6,7,8,9,10,11,22}
print(nums1 | nums2) # Union
print(nums1 & nums2) # Intersection
print(nums1 - nums2) # Difference
print(nums1 ^ nums2) # Symmetric Difference
nums1=[1,2,3,1,3,4,10,5,6,6,7,8,9,10]
nums2=[1,2,3,1,3,4,10,5,6,6,7,8,9,10]
uniques1=set(nums1)
uniques2=set(nums2)
print(uniques1 | uniques2)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''
Did you know you can create variables for some of these Python
commands/functions? This will give us much more opportunities
to use variables as Python code in a for loop that loops through
a list of values, which are actual Python commands/functions.
You can create two or more Python commands/functions with
just one for loop alone. Let's explore what these variables can
do for us, using actual Python code itself.
'''
absolute_num = abs
add_nums = sum
ascii_character = ascii
ascii_character_num = ord
ascii_character_value = chr
binary_base_2 = bin
character_string = str
convert_to_list = list
convert_to_set = set
convert_to_tuple = tuple
dictionary = dict
float_num = float
George_Boole = bool
hexadecimal_base_16 = hex
index_error = IndexError
integer_num = int
maximum_num = max
memory_error = MemoryError
minimum_num = min
redundant_code = exec
round_num = round
super_function = super
text_input = input
text_print = print
value_error = ValueError
value_length = len
you_quitter = quit
must_exit = exit
# Let's try a simple print() command/function and see what this does
# We will also create a variable to be a text placeholder, so we don't
# have to keep rewriting text sentences over and over again.
text = "This was Python's print() command/function."
# this:
print("This was Python's print() command/function.")
# or this:
text_print(text) # use variables instead if you like
# Let's try a few more to get the hange of things. Let's add some numbers
# together with the sum() command/function, we renamed to 'add_nums'
# using a variable to store the actual sum() command/function. We also
# need to create a variable we'll call nums, so we can store a default tuple
# of numbers without any parenthesese, ie: (1,2,3,4,5,6,7,8,9)
nums = 1,2,3,4,5,6,7,8,9 # this is a tuple by default, without parentheses ' () '
# this:
print(sum(nums))
# or this:
text_print(add_nums(nums))
# Let's try a simple input() command/function and see what this does We will
# create a variable to be a text placeholder, so we don't have to keep rewriting
# text sentences over and over again. We also have to create an 'user_input'
# variable so the user can type into it.
input_text = "This was Python's input() command/function."
# this:
user_input = input("This was Python's input() command/function.")
# or this:
user_input = text_input(input_text)
# Let's use a for loop to loop through a tuple of variables, which are actual Python
# commands/functions. Let's creat our tuple called loop.
loop = integer_num,binary_base_2,hexadecimal_base_16
for i in loop:
text_print(f'{i(255)}. You only need one print statement with a list of variables.')