-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMy Python Journal.txt
More file actions
1204 lines (904 loc) · 35.6 KB
/
Copy pathMy Python Journal.txt
File metadata and controls
1204 lines (904 loc) · 35.6 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
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Adrian Guillory (Dack Dissident)
Python Journal
Class 2
#Lab 1 Strings. below are a bunch of strings that we have written within our first python file
#this is an example of a normal string
print("My first string was created on 16 April 2023. I am so happy to have begun my python journey!")
print("I love being a passport bro")
print("I am conflicted between latina women and asian women")
print("In the last two weeks, I have found myself liking south korean women more")
print("I hope to one day meet a half brazilian, quarter japanese, and quarter korean woman!")
print("I used to crush hard on Mariah Carey")
#this is an example of how to put quotations into a string
print("\"Bruh!\" Julius Irving is the greatest basketball player ever!")
print("The best Brazilian movie of all time is \"City Of God\".")
#this is an example of how to put a new line into a string
print("New\nline")
print("Lebron James is NOT a better basketball player than \nMichael Jordan")
#Lab 2 Variables
#Lab 2 Variables These were the first variables we have written in the class
#this is an example of a variable
my_str = "Michael Jordan Only won the NBA championship with one team. But LeBron won it with three!"
print(my_str)
my_str_another = "Allen Iverson may not have won a NBA championship, but he was technically better than MJ"
print(my_str_another)
blue = "This is what the sky looks like!"
print(blue)
blue_green_orange_purple = "These colours are terrible!"
print(blue_green_orange_purple)
#this is an example of how to use variables to deploy massive changes to a lot of code
character_name = "Anis Bryant"
character_age = "22"
character_job = "The CEO of Microsoft and Twitter"
character_country = "japan"
print("There was a passport bro called " +character_name+",")
print("he is " +character_age+ " years old")
print("He works as " +character_job+ ".")
print("He got married to a beautiful half brazilian half japanese woman from " +character_country+ ".")
Lab 3 Comments
#this is an example of a comment the hashtag at the beinning let's pythond know what we are working at a comment
#Lab 2 Variables These were the first variables we have written in the class
character_name = "International Passport"
character_age = "45"
character_job = "IT Professional"
character_country = "panama"
print("There was a passport bro called " +character_name+",")
print("he is " +character_age+ " years old")
print("IP works as an " +character_job+ ".")
print("He got married to a beautiful black woman from " +character_country+ ".")
_____________________________________________________________________________
04-23-2023 Class 3 Notes
#Storing numbers within variables
my_num = 50
print(my_num)
my_num = 150
print(my_num)
my_num = 200
print(my_num)
my_number = 10
print(my_number)
number_my = 5
print(number_my)
#Using the str() function to convert a number into a string
my_num = 90
print(str(my_num) + " is the best number ever!")
#assigned by IP to repeat first lab of Class 3
my_num = 31
print(my_num)
#Common number functions to use in python
#abs function - this prints the absolute value of a number
my_num = -80
print(abs(my_num))
my_num2 =-50
print(abs(my_num2))
my_num3 = -15
print(abs(my_num3))
my_num4 = -10
print(abs(my_num4))
my_num5 = -20
print(abs(my_num5))
my_num = 59
print(my_num)
#power function - this allows us to pass in two pieces of numerical information to get the power result from the number
print(pow(3,5))
print(pow(4,9))
print(pow(8,100))
print(pow(90,40))
print(pow(4,9))
#max function - this gives you the highest number out of the numbers you put in the brackets
print(max(4,2))
print(max(8,100))
print(max(50,20))
print(max(1,2))
print(max(45,97))
#main function - this is the opposite of the max function - minimum number from two numerical values
print(min(2,1))
print(min(5,9))
print(min(10,15))
print(min(4,16))
print(min(100,250))
print(min(30,40))
#round function - this rounds the number to it's correct value
print(round(8.6))
print(round(7.1))
print(round(9.0))
print(round(5.2))
print(round(8.7))
#import function - used to import other maths functions to use in your python program
#from this math module to import the math function
from math import *
print(sqrt(90))
print(sqrt(150))
print(sqrt(20))
print(sqrt(35))
print(sqrt(70))
#import function - used to import other maths functions to use in your python program
#from this math module to import the math function
from math import *
print(tan(40))
print(tan(20))
print(tan(90))
print(tan(65))
print(tan(23))
_____________________________________________________________________________
05-14-2023 Class 4 Notes
#lab 1 - working on the input function
name = input("Enter Your Name To Start The Game: ")
level = input("Enter Your Level Number To Continue The Game: ")
print("Hello " + name + " ! You are at Level " + level)
#input() starts the game, asks for name
#print('string' + input function + 'string'2 + ... + input function n + 'string'n) prints out the inputs
-----------------------------------------------------------------------------
#lab 2 - building a calculator using the input function
number1 = input("Please enter a number: ")
number2 = input("Please enter a second number: ")
result = int(number1) + int(number2)
print(result)
# + is to add, * is to multiply, / is to divide
#int() is a function for an integer a of whole number. Converts the string 'number1' to a number.
#without int(), it only prints out the strings
#float() function is for a decimal number
#when using math function, float() must be used for non-integer results
-----------------------------------------------------------------------------
#lab 3 - use input function to rate a user's mood
print("Hi user, how would you rate your mood on a scale of 1 to 10?")
mood_rating = input()
print("You feel like a " + mood_rating + "." "\nThanks for letting us know!")
#used in rating a customer service
_____________________________________________________________________________
05-21-2023 Class 5 Notes
Lists
#lab 1 - creating our first list
anime = ["Naruto","Shingeki No Kyojin", "Bleached", "Yu Yu Hakusho", "Dragonball Z"]
#List ["Naruto",...,"Dragonball Z"] is stored in the variable anime
#Lists are in [] - square brackets
print(anime)
-----------------------------------------------------------------------------
#lab 2 - print out a specific element or value from this list
cars = ["Telsa", "BMW", "Nissan GTR", "Ferrari", "Ford"]
print(cars[4])
#using a negative 1 gives last element first, [-2] gives second to last element second, and so on
-----------------------------------------------------------------------------
#lab 3 - printing multiple elements from your list
laptops = ["Lenovo", "Apple", "HP", "Dell", "Samsung"]
print(laptops[1:])
#pring(laptops[1:]) only prints out elements from Apple and onwards
print(laptops[2:])
print(laptops[3:])
print(laptops[0:3])
#print(laptops[0:3]) prints out elements 0 to 2
#print(laptops[0:n+1]) prints out range of elements from 0 to n from the list
print(laptops[0:4])
-----------------------------------------------------------------------------
#lab 4 - modifying a value in your list and updating it
anime = ["Bleach", "Naruto", "Captain Tsubasa", "One Piece", "Dragonball"]
anime [3] = "Slam Dunk"
#One Piece is replaced with Slam Dunk by calling anime element 3
print(anime[3])
_____________________________________________________________________________
05-28-2023
Class 6 Notes
#List Functions
#Lab 1 - extend function
anime = ["Naruto","Bleach", "Attack On Titan", "Captain Tsubasa", "Dragon Ball Z"]
cars = ["Tesla", "BMW", "Range Rover", "Aston Martin", "Mercedes"]
#anime.extend() adds cars to anime list
anime.extend(cars)
print(anime)
-----------------------------------------------------------------------------
#Lab 2 - append function
anime = ["Naruto","Bleach", "Attack On Titan", "Captain Tsubasa", "Dragon Ball Z"]
cars = ["Tesla", "BMW", "Range Rover", "Aston Martin", "Mercedes"]
#anime.append() adds element(s) to the end of Dragon Ball Z
anime.append("Death Note")
print(anime)
-----------------------------------------------------------------------------
#Lab 3 - insert function
anime = ["Naruto","Bleach", "Attack On Titan", "Captain Tsubasa", "Dragon Ball Z"]
cars = ["Tesla", "BMW", "Range Rover", "Aston Martin", "Mercedes"]
#anime.insert(n, element) adds element beginning at position n
anime.insert(4, "Gundam")
print(anime)
-----------------------------------------------------------------------------
#Lab 4 - remove function
anime = ["Naruto","Bleach", "Attack On Titan", "Captain Tsubasa", "Dragon Ball Z"]
cars = ["Tesla", "BMW", "Range Rover", "Aston Martin", "Mercedes"]
#anime.remove(elment) removes element from list. must match case. case-sensitive
anime.remove("Bleach")
print(anime)
-----------------------------------------------------------------------------
#Lab 5 - clear function
anime = ["Naruto","Bleach", "Attack On Titan", "Captain Tsubasa", "Dragon Ball Z"]
cars = ["Tesla", "BMW", "Range Rover", "Aston Martin", "Mercedes"]
#anime.clear() clears list.
anime.clear()
print(anime)
-----------------------------------------------------------------------------
#Lab 6 - index function
anime = ["Naruto","Bleach", "Attack On Titan", "Captain Tsubasa", "Dragon Ball Z"]
cars = ["Tesla", "BMW", "Range Rover", "Aston Martin", "Mercedes"]
#anime.index() tells you the numerical value of element from list.
print(anime.index("Attack On Titan"))
-----------------------------------------------------------------------------
#Lab 7 - count function
anime = ["Naruto","Bleach", "Bleach", "Bleach", "Bleach", "Attack On Titan", "Captain Tsubasa", "Dragon Ball Z"]
cars = ["Tesla", "BMW", "Range Rover", "Aston Martin", "Mercedes"]
#anime.count() tells you how many times value appears in the list.
print(anime.count("Bleach"))
-----------------------------------------------------------------------------
#Lab 8 - sort function
anime = ["Naruto","Bleach", "Bleach", "Bleach", "Bleach", "Attack On Titan", "Captain Tsubasa", "Dragon Ball Z"]
cars = ["Tesla", "BMW", "Range Rover", "Aston Martin", "Mercedes"]
#anime.sort() sorts list in alphabetical or ascending order.
anime.sort()
print(anime)
numbers = [8,9,2,5, 1]
#numbers.sort() sorts list in numerical order
numbers.sort()
print(numbers)
-----------------------------------------------------------------------------
#Lab 9 - reverse function
anime = ["Naruto", "Bleach", "Attack On Titan", "Captain Tsubasa", "Dragon Ball Z"]
cars = ["Tesla", "BMW", "Range Rover", "Aston Martin", "Mercedes"]
#anime.reverse() sorts list in reverse order.
anime.reverse()
print(anime)
______________________________________________________________________________
06-04-2023
Class 7 Notes
#Tuples
#Lab1 - Creating our first tuple
#tuple uses parenthesis
tuple = ("Tesla", "Bentley", "Hummer", "Jeep", "Ferrari")
print(tuple)
anime = ("Naruto", "Bleach", "Dragon Ball", "Hunter x Hunter")
print(anime)
laptops = ("HP", "Samsung", "Apple", "Sony")
print(laptops)
numbers = (5, 9, 2, 1, 0)
print(numbers)
countries = ("Japan", "Spain", "Morocco", "Canada")
print(countries)
----------------------------------------------------------------------------------
#Lab 2 - printing a single value from our tuple
tuple = ("Tesla", "Bently", "Ferrari", "Nissan", "BMW")
#tuples also start their elements from 0 like listss
#Print out only Tesla at position 0 using brackets
print(tuple[0])
-----------------------------------------------------------------------------------
#Lab 3 - example on why tuples are immutable (meaning they cannot be changed)
tuple = ("Tesla", "Bently", "Hummer", "Jeep", "Ferrari")
#Change Bently to Nissan
tuple[1] = "Nissan"
#print Nissan in output
print(tuple[1])
#Terminal Output - tuple[1] = "Nissan"
#TypeError: 'tuple' object does not support item assignment
#Use lists to change, not tuples
-----------------------------------------------------------------------------------
#Lab 4 - Examples on why lists are mutable (meaning they can be changed)
#tuple is now a list with square brackets
tuple = ["Tesla", "Bently", "Hummer", "Jeep", "Ferrari"]
#Change Jeep To Nissan
tuple[3] = "Nissan"
print(tuple[3])
___________________________________________________________________________________
06-11-2023
Class 8 Notes
#Complex Functions
#Lab 1 - creating our first function
#def tells Python to create or use a function
#what_car_you_drive is the new function
def what_car_you_drive():
#print function is installed or inside the function
print("I Drive a Tesla")
#include a () at the end to ensure the output is shown
what_car_you_drive()
#Complex Functions
#Lab 2 - another function exercise
#Defined the function named 'the()'
def the():
#indented to include print function
print("The")
print("Enter")
the()
print("Game")
---------------------------------------------------------------------------
#Lab 3 - slightly more complex function code
#include model inside function parentheses
#called a parameter
def make(model):
#the plus (+) operator includes parameter inside print function
print("Blue " + model)
#inserting car models inside the make function
#all the strings are linked back to make() function
make("Tesla")
make("Nissan")
make("Benz")
----------------------------------------------------------------------------
#Lab 4 - another complex function code
#add 2 parameters in the function, name and height
#function defined is only to accept two parameters
def introductions(name, height):
print("Good Afternoon "+ name + " you work in IT and you are " + height)
#each parameter below matches the original function
introductions("Edwin", "190 CM")
introductions("Jason", "185 CM")
introductions("Hannah", "120 CM")
introductions("Keisha", "570 CM")
----------------------------------------------------------------------------
#Lab 5 - using tuples within a function
#include asterisk * before cars parameter for vehicles() function
def vehicles(*cars):
#include [] after cars to name a specific position in the tuple
print("The best car in the world is " +cars[4])
#calls back from vehicle() to use this tuple
vehicles("Tesla", "Mercedes", "Range Rover", "Nissan", "Ferrari")
----------------------------------------------------------------------------
#Lab 6 - adding numbers together using the return statement in our function
#defining a function 'add' to add numbers
def add():
#return tells Python user is using the return function to add numbers
return 8+3+10
print(add())
-----------------------------------------------------------------------------
#Lab 7 - mutliplying numbers with the return statement in our function
#defining function as mulitply() to multiply 2 parameters, 'num1' and 'num2'
def multiply(num1,num2):
#tell Python to multiply num1 and num2
#defined as result
result = num1 * num2
#return result
return result
#multiply 5 * 5
#print result
print(multiply(5,5))
______________________________________________________________________________
06-18-2023
Class 9 Notes
#Dictionary Methods
#Lab 1 - writing our first dictionary and calling from it
NbaMostValuablePlayerAward = {
#2013 is the first key for MVP Award dictionary
#Lebron James - the key value 2013
#key is separated by colon
2013: "Lebron James",
2014: "Kawhi Leonard",
2015: "Andrew Iguodala",
2016: "Lebron James",
2017: "Kevin Durant",
2018: "Kevin Durant",
2019: "Kawhi Leonard",
2020: "Lebron James",
2021: "Giannis Antetokoumpo",
2022: "Stephen Curry",
2023: "Nikola Jokic"
}
#print dictionary name ['dictionary key']
print(NbaMostValuablePlayerAward[2022])
------------------------------------------------------------------------------
#Lab 2 - another example of a dictionary
movie = {
#key is now a regular string 'title'
"title": "Goodfellas",
"Director": "Martin Scorcese",
#key value can either be a number or a string
"Year": 1990,
"Rating": 9.5
}
#print dictionary ['key string name']
print(movie["Year"])
-----------------------------------------------------------------------------
#Lab 3 - updating the movie value score
movie = {
#key is now a regular string 'title'
"title": "Goodfellas",
"Director": "Martin Scorcese",
#key value can either be a number or a string
"Year": 1990,
"Rating": 9.5
}
#update key string 'Rating' to a different key value
#you must express updated key value, defined as dictionary[key string name] + 2
#use parentheses
movie["Rating"] = (movie["Rating"] + 2)
#print dictionary ['Rating']
#case-sensitive is important in key string name
print(movie["Rating"])
-------------------------------------------------------------------------------
#Lab 4 - store a list inside of a dictionary and store a dictionary within that dictionary
movie = {}
#movie[] are contained inside the movie {}
#different syntax, same logic
movie["title"] = "City of God"
movie["Director"] = "Fernando Meirelles"
movie["Year"] = 2002
movie["Rating"] = 8.2
#creating list "Actors" within movie
#still contained in the movie dictionary
movie["Actors"] = ["Alexandre Rodirgues", "Alice Braga", "Douglas Silva"]
#create a dictionary 'more facts' in the movie dictionary
movie["more_facts"] = {
"movielength": 180,
"language": "English"
}
#prints list within a dictionary and a sub-dictionary ' more_facts ' within the primary dictionary 'movie'
print(movie)
----------------------------------------------------------------------------------
#Lab 5 - Dictionary lab with .get example
NbaMostValuablePlayerAward = {
2019: "Kawhi Leonard",
2020: "Lebron James",
2021: "Giannis Anteokoumpo",
2022: "Stephen Curry",
2023: "Nikola Jokic"
}
#print Stephen Curry from dictionary with get() dictionary functoin
print(NbaMostValuablePlayerAward.get(2022))
----------------------------------------------------------------------------------
#Lab 6 - Dictionary lab with .values example
NbaMostValuablePlayerAward = {
2019: "Kawhi Leonard",
2020: "Lebron James",
2021: "Giannis Anteokoumpo",
2022: "Stephen Curry",
2023: "Nikola Jokic"
}
#print all values from dictionary with values() dictionary functoin
print(NbaMostValuablePlayerAward.values())
----------------------------------------------------------------------------------
#Lab 7 - Dictionary lab with .keys example
NbaMostValuablePlayerAward = {
2019: "Kawhi Leonard",
2020: "Lebron James",
2021: "Giannis Anteokoumpo",
2022: "Stephen Curry",
2023: "Nikola Jokic"
}
#print dictionary keys from dictionary with keys() dictionary functoin
print(NbaMostValuablePlayerAward.keys())
--------------------------------------------------------------------------------
#Lab 8 - Dictionary lab with .copy example
NbaMostValuablePlayerAward = {
2019: "Kawhi Leonard",
2020: "Lebron James",
2021: "Giannis Anteokoumpo",
2022: "Stephen Curry",
2023: "Nikola Jokic"
}
#print everything from dictionary with copy() dictionary function
print(NbaMostValuablePlayerAward.copy())
_____________________________________________________________________________
06-25-2023 Class 10 Notes
#Conditional Logic
#Lab 1 - if statement example
#introduce two variables C and D
c = 50
d = 400
#conditional logic
if d > c:
print("D is greater than C")
------------------------------------------------------------------------------
#Lab 2 - if statement complex example
price = input("How Much Did You Pay?")
#convert string (price) into a number/integer
price = int(price)
if price >= 100:
tax = .07
#print output
#convet tax to a string
print("Your Tax rate is: " +str(tax))
------------------------------------------------------------------------------
#Lab 3 - else statement example
c = 400
d = 50
#end conditional statements if/then with a colon(:)
if d > c:
print("D is greater than C")
else:
print("C is greater than D")
------------------------------------------------------------------------------
#Lab 4 - else statement complex example
price = input("How Much Did You Pay?")
price = int(price)
if price >= 100:
tax =.07
print("Tax rate is: " + str(tax))
else:
tax = 0
print("Tax rate is: " + str(tax))
------------------------------------------------------------------------------
#Lab 5 - elif statement example
c = 50
d = 50
if d > c:
print("D is greater than C")
elif c == d:
print("C and D are equal")
------------------------------------------------------------------------------
#Lab 6 - bringing if, elif and else altogether
c = 51
d = 50
if d > c:
print("D is greater than C")
elif c == d:
print("C and D are equal")
else:
print("C is greater than D")
------------------------------------------------------------------------------
#Lab 7 - And operator lab
k = 500
z = 200
i = 800
#both conditions must be true with the 'and' operator
if i > k and i > z:
print("Both conditions are true!")
------------------------------------------------------------------------------
#Lab 8 - Or operator lab
k = 500
z = 200
i = 800
if i > k or z > i:
print("One of the conditions is indeed true!")
------------------------------------------------------------------------------
#Lab 9 - Not operator lab
k = 500
z = 200
i = 800
if not k > i :
print("It appears K is not greater than I!")
______________________________________________________________________________
07-02-2023 Class 11 Notes
While Loop
#Lab 1 - our first while loop example
i = 1
while i <= 10:
print(i)
# '+= ' operator adds two variables together (i and 1)
# '=' adds value to the last variable
i += 1
print("The Loop Ends Here!")
------------------------------------------------------------------------------
#Lab 2 - never ending loop example
i = 1
while i <= 10:
print(i)
print("The Loop Ends Here!")
-------------------------------------------------------------------------------
#Lab 3 - while loop with statements
i = 1
while i <= 5:
print("Bleach")
#recursion formula
i = i + 1
--------------------------------------------------------------------------------
#Lab 4 - f string lab
#define car variable equal to "Tesla"
car = "Tesla"
#f string is used to include the 'car' variable with {}
#f string allows you to pull any variable from code
print(f"The Car I Drive Is {car}")
---------------------------------------------------------------------------------
#Lab 5 - combine while loop with the input function and f strings
name = input("Enter Your Name To Begin The Game: ")
while name == "":
print("Player One Did Not Enter His Name")
name = input("Enter Your Name To Begin The Game: ")
# f string pulls name from the while loop
print(f"Welcome {name}")
----------------------------------------------------------------------------------
#Lab 6 - More complex while code
age = int(input("Enter Your Age To Begin The Game: "))
while age < 0:
#code breaks at age 90 and above
print("Age Can't Be Negative")
age = int(input("Enter Your Age To Begin The Game: "))
print(f"You are {age} years old!")
-------------------------------------------------------------------------------------
#Lab 7 - Using the NOT operator with while loops
anime = input("Enter an anime series that you like (press q to quit): ")
while not anime == "q":
#q will end the loop
# without q, the loop will continue to run
print(f"You like {anime}")
anime = input("Enter another anime series that you like (press q to quit): ")
print("Thanks for letting us know what anime shows you like!")
-------------------------------------------------------------------------------------
#Lab 8 - Uing the OR operator with while loops
#convert string into a number with int()
num = int(input("Enter a Number Between 1 - 20: "))
while num < 1 or num > 20:
#f string pulls num from the while loop
print(f"{num} is not valid")
num = int(input("Enter a Number Between 1 - 20: "))
#loop breaks when num is valid
print(f"Your Number is {num}")
____________________________________________________________________________________
07-09-2023
Class 12 Notes
#For Loop
#Lab 1 - applying 'for' loop for a string
#for loop includes in for Python
#letter is the name of the for loop
#in is the for loop syntax in Python
for letter in "Naruto Uzumaki":
#Loops or iterates through every single letter in Naruto Uzumaki
print(letter)
------------------------------------------------------------------------------------
#Lab 2 - applying 'for' loop to a list
#Use for loop to iterate bits of code to make statement true
animecharacters = ["Goku", "Vegeta", "Piccolo", "Chi Chi"]
#apply for loop to go through each string in the list
for anime in animecharacters:
#Prints out every individual string in the animecharacters list
#Loop ends at Chi Chi
print(anime)
------------------------------------------------------------------------------------
#Lab 3 - applying for loop to a series of numbers with the range function
#Range function returns a sequence of numbers between the given range
for index in range(20):
#For loop loops from 0 to 19
print(index)
------------------------------------------------------------------------------------
#Lab 4 - applying for loop to a series of a specific range of numbers
#10 and 20 are the allowed ages to play game
#index is the name of the for loop
for index in range (10, 21):
#For loops through numbers 10 through 20
print(index)
------------------------------------------------------------------------------------
#Lab 5 - applying for loop to break statements
#Creating a list of cars
cars = ["Tesla", "BMW", "Mercedes", "Hummer"]
for x in cars:
print(x)
#if the loop reaches specific element, Break the for loop, e.g. "BMW"
if x == "BMW":
break
------------------------------------------------------------------------------------
#Lab 6 - applying for loop to continue staements
laptops = ["Lenovo", "HP", "Mac", "Dell", "Toshiba"]
for y in laptops:
#Use continue to remove HP and continue through the loop
if y == "HP":
continue
#prints out all elements except HP
print(y)
------------------------------------------------------------------------------------
#Lab 7 - applying for loop to else statements
animecharacters = ["Vegeta", "Goku", "Piccolo", "Chi Chi", "Yamcha"]
for x in animecharacters:
print(x)
else:
print("These Are Some The Characters From Dragonball Z.")
------------------------------------------------------------------------------------
#Lab 8 - applying for loop to the end= parameter
animecharacters = ["Vegeta", "Goku", "Piccolo", "Chi Chi", "Yamcha"]
for anime in animecharacters:
#prints all the elements of the loop in one line
#can be used for managerial, system purposes
print(anime, end="")
____________________________________________________________________________________
07-16-2023
Class 13 Notes
#Try Except
#Lab 1 - A program that works correctly
number = int(input("Enter a Number to Start the Game: "))
print(number)
#this only works for numbers
------------------------------------------------------------------------------------
#Lab 2 - A program that does not work correctly
#code breaks with a letter / string
number = int(input("Enter a Number to Start the Game: "))
print(number)
------------------------------------------------------------------------------------
#Lab 3 - Applying the try except principle to our code
try:
number = int(input("Enter a Number to Start the Game: "))
print(number)
#if input is a non-integer, use except
except:
print("Invalid Input, You Did Not Enter a Number! Please Try Again!")
#if statement does not work for try except
#Try except is a Python Best Practice for Error Detection / Error Messaging in Code
#Try except is for front-end user error detection
------------------------------------------------------------------------------------
#Lab 4 - Another example of try except to our code
#anything outside the try except block will be excluded from block
try:
number = 50/0
number = int(input("Enter A Number: "))
print(number)
except:
print("Invalid Input, please try again")
____________________________________________________________________________________
07-23-2023
Class 14 Notes
#Lab 1 - creating a text file animelist.txt
Naruto
Bleach
Dragonball Z
Demon Slayer
------------------------------------------------------------------------------------
#Lab 2 - using specific functions if our file can be read
#open() opens the file with read permission roperties only (r)
anime_file = open("animelist.txt","r")
#readable() lets you know whether or not the file can be read
#outputs with true or false (not readable)
print(anime_file.readable())
#close() lets you close file
#python best practice to close file after making changes to original file
#protects file for security purposes and unexpected changes
anime_file.close()
------------------------------------------------------------------------------------
#Lab 3 - reading the contents of a file
anime_file = open("animelist.txt","r")
print(anime_file.read())
anime_file.close()
#Python is change-sensitive
#always save opened file prior to running code
-----------------------------------------------------------------------------------
#Lab 4 - read an individual line from our file
anime_file = open("animelist.txt","r")
#readline() will read the first line in the text file
print(anime_file.readline())
anime_file.close()
------------------------------------------------------------------------------------
#Lab 5 - using the .readlines() function to read a specific line we need
anime_file = open("animelist.txt","r")
#readlines() will read the text file
#a [] after .readlines() allows you to print out a specific element from the text file
print(anime_file.readlines()[2])
anime_file.close()
------------------------------------------------------------------------------------
#Lab 6 - adding to our list using the (a)ppend mode