Skip to content

Commit bd666b9

Browse files
committed
update code
1 parent 28fa020 commit bd666b9

File tree

2 files changed

+2895
-40
lines changed

2 files changed

+2895
-40
lines changed

Code/01_foundation_oop.ipynb

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@
5858
},
5959
{
6060
"cell_type": "code",
61-
"execution_count": 1,
61+
"execution_count": null,
6262
"metadata": {},
6363
"outputs": [],
6464
"source": [
65-
"from colorama import Fore "
65+
"from colorama import Fore \n"
6666
]
6767
},
6868
{
@@ -112,7 +112,7 @@
112112
},
113113
{
114114
"cell_type": "code",
115-
"execution_count": 2,
115+
"execution_count": null,
116116
"metadata": {},
117117
"outputs": [
118118
{
@@ -148,7 +148,7 @@
148148
"print(Fore.GREEN + f\"{obj2.name = :5} {obj2.lname = :5} {obj2.age = }\")\n",
149149
"\n",
150150
"print(Fore.BLUE + f\"{55 * \"=\"} Dict {54 * \"=\"}\\n{obj1.__dict__ = }\")\n",
151-
"print(Fore.BLUE + f\"{obj2.__dict__ = }\")"
151+
"print(Fore.BLUE + f\"{obj2.__dict__ = }\")\n"
152152
]
153153
},
154154
{
@@ -174,7 +174,7 @@
174174
},
175175
{
176176
"cell_type": "code",
177-
"execution_count": 3,
177+
"execution_count": null,
178178
"metadata": {},
179179
"outputs": [
180180
{
@@ -208,7 +208,7 @@
208208
"\n",
209209
"print(Fore.BLUE + f\"\\n{55 * \"=\"} Dict {54 * \"=\"}\")\n",
210210
"print(f\"{obj1.__dict__ = }\")\n",
211-
"print(f\"{obj2.__dict__ = }\")"
211+
"print(f\"{obj2.__dict__ = }\")\n"
212212
]
213213
},
214214
{
@@ -231,7 +231,7 @@
231231
},
232232
{
233233
"cell_type": "code",
234-
"execution_count": 4,
234+
"execution_count": null,
235235
"metadata": {},
236236
"outputs": [
237237
{
@@ -264,12 +264,12 @@
264264
"\n",
265265
"# ----------------- Access attributes & print the name, lname, age, and pay of each object ---------------------\n",
266266
"print(f\"{obj1.name = :5} {obj1.lname = :5} {obj1.age = :2} {obj1.pay = }\")\n",
267-
"print(f\"{obj2.name = :5} {obj2.lname = :5} {obj2.age = :2} {obj2.pay = }\")"
267+
"print(f\"{obj2.name = :5} {obj2.lname = :5} {obj2.age = :2} {obj2.pay = }\")\n"
268268
]
269269
},
270270
{
271271
"cell_type": "code",
272-
"execution_count": 5,
272+
"execution_count": null,
273273
"metadata": {},
274274
"outputs": [
275275
{
@@ -290,12 +290,12 @@
290290
"obj2.pay_increase() # Call method to increase pay for object2\n",
291291
"\n",
292292
"# Print the updated pay values for both objects\n",
293-
"print(f\"{obj1.pay = }, {obj2.pay = }\")"
293+
"print(f\"{obj1.pay = }, {obj2.pay = }\")\n"
294294
]
295295
},
296296
{
297297
"cell_type": "code",
298-
"execution_count": 6,
298+
"execution_count": null,
299299
"metadata": {},
300300
"outputs": [
301301
{
@@ -319,12 +319,12 @@
319319
"obj2.pay_increase() # Increases pay for object2 with the original class variable value\n",
320320
"\n",
321321
"# Print the updated pay values for both objects\n",
322-
"print(Fore.GREEN + f\"{obj1.pay = }, {obj2.pay = }\")"
322+
"print(Fore.GREEN + f\"{obj1.pay = }, {obj2.pay = }\")\n"
323323
]
324324
},
325325
{
326326
"cell_type": "code",
327-
"execution_count": 7,
327+
"execution_count": null,
328328
"metadata": {},
329329
"outputs": [
330330
{
@@ -339,7 +339,7 @@
339339
],
340340
"source": [
341341
"# Display all instance-specific and class-wide properties ----------------------------\n",
342-
"print(Fore.MAGENTA+ f\"{obj1.__dict__ = }\\n{obj2.__dict__ = }\\n{Person.__dict__ = }\")"
342+
"print(Fore.MAGENTA+ f\"{obj1.__dict__ = }\\n{obj2.__dict__ = }\\n{Person.__dict__ = }\")\n"
343343
]
344344
},
345345
{
@@ -370,7 +370,7 @@
370370
},
371371
{
372372
"cell_type": "code",
373-
"execution_count": 8,
373+
"execution_count": null,
374374
"metadata": {},
375375
"outputs": [
376376
{
@@ -393,7 +393,7 @@
393393
" users = [] # Class variable to store list of user names\n",
394394
" users_course = {} # Class variable to store dictionary mapping user names to their courses\n",
395395
" \n",
396-
" def __init__(self, name: str, email: str, password: int, receive):\n",
396+
" def __init__(self, name: str, email: str, password: int, receive: bool):\n",
397397
" self.name = name # Instance variable to store the student's name\n",
398398
" self.email = email # Instance variable to store the student's email\n",
399399
" self.password = password # Instance variable to store the student's password\n",
@@ -407,21 +407,21 @@
407407
" else:\n",
408408
" print(f\"{name} must register.\") # Indicates the user must register\n",
409409
" \n",
410-
" def buy(self, coursename: str): # Method to assign a course to the student\n",
411-
" Student.users_course[self.name] = coursename # Maps the student's name to the purchased course\n",
412-
" print(f\"{self.name} has purchased the course: {coursename}\\n\")\n",
410+
" def buy(self, course_name: str): # Method to assign a course to the student\n",
411+
" Student.users_course[self.name] = course_name # Maps the student's name to the purchased course\n",
412+
" print(f\"{self.name} has purchased the course: {course_name}\\n\")\n",
413413
"\n",
414414
"# Create an object of the class\n",
415-
"obj1 = Student(\"Stud1\", \"Stud1@.com\", \"2547\", True) # Creates an instance of `student` named \"Stud1\"\n",
415+
"obj1 = Student(\"Stud1\", \"Stud1@.com\", 254, True) # Creates an instance of `student` named \"Stud1\"\n",
416416
"obj1.buy(\"matlab\") # The student \"aa\" purchases the \"matlab\" course\n",
417417
"\n",
418-
"obj2 = Student(\"Stud2\", \"Stud2@.com\", \"247\", True) # Creates another instance of `student` named \"Stud2\"\n",
419-
"obj2.buy(\"python\") # The student \"rr\" purchases the \"python\" course"
418+
"obj2 = Student(\"Stud2\", \"Stud2@.com\", 247, True) # Creates another instance of `student` named \"Stud2\"\n",
419+
"obj2.buy(\"python\") # The student \"rr\" purchases the \"python\" course\n"
420420
]
421421
},
422422
{
423423
"cell_type": "code",
424-
"execution_count": 9,
424+
"execution_count": null,
425425
"metadata": {},
426426
"outputs": [
427427
{
@@ -435,12 +435,12 @@
435435
],
436436
"source": [
437437
"# Student users & courses\n",
438-
"print(f\"{Student.users = }\\n{Student.users_course = }\")"
438+
"print(f\"{Student.users = }\\n{Student.users_course = }\")\n"
439439
]
440440
},
441441
{
442442
"cell_type": "code",
443-
"execution_count": 10,
443+
"execution_count": null,
444444
"metadata": {},
445445
"outputs": [
446446
{
@@ -457,14 +457,14 @@
457457
"source": [
458458
"# Update student users & courses\n",
459459
"obj2.login(\"Stud3\") # Attempts to log in a user named \"Stud3\", expected print: \"Stud3 must register.\"\n",
460-
"obj3 = Student(\"Stud3\", \"Stud3@.com\", \"5478\", True) # Creates a new instance of `student` named \"Stud3\"\n",
460+
"obj3 = Student(\"Stud3\", \"Stud3@.com\", 5478, True) # Creates a new instance of `student` named \"Stud3\"\n",
461461
"obj3.login(\"Stud3\") # Now attempts to log in \"Stud3\" again, expected print: \"Stud3 has an account.\"\n",
462462
"print(Fore.MAGENTA + f\"{Student.users = }; {Student.users_course = }\") # Prints the updated list of user names, courese\n"
463463
]
464464
},
465465
{
466466
"cell_type": "code",
467-
"execution_count": 11,
467+
"execution_count": null,
468468
"metadata": {},
469469
"outputs": [
470470
{
@@ -478,7 +478,7 @@
478478
}
479479
],
480480
"source": [
481-
"print(Fore.CYAN + f\"{obj1.__dict__ = }\\n{obj2.__dict__ = }\\n{obj3.__dict__ = }\")"
481+
"print(Fore.CYAN + f\"{obj1.__dict__ = }\\n{obj2.__dict__ = }\\n{obj3.__dict__ = }\")\n"
482482
]
483483
},
484484
{
@@ -495,7 +495,7 @@
495495
},
496496
{
497497
"cell_type": "code",
498-
"execution_count": 12,
498+
"execution_count": null,
499499
"metadata": {},
500500
"outputs": [
501501
{
@@ -523,7 +523,7 @@
523523
" users = [] # Class variable that keeps a list of user names\n",
524524
" users_course = {} # Class variable that maps user names to their purchased courses\n",
525525
" \n",
526-
" def __init__(self, name: str, email: str, password: int, receive):\n",
526+
" def __init__(self, name: str, email: str, password: int, receive: bool):\n",
527527
" self.name = name # Instance variable for storing the student's name\n",
528528
" self.email = email # Instance variable for storing the student's email\n",
529529
" self.password = password # Instance variable for storing the student's password\n",
@@ -547,25 +547,25 @@
547547
" else:\n",
548548
" print(f\"{name} must register.\\n\") # Message indicating the user needs to register\n",
549549
" \n",
550-
" def buy(self, coursename: str): # Method to assign a course to a student\n",
551-
" Student.users_course[self.name] = coursename # Maps the course name to the student in `users_course`\n",
552-
" print(f\"{self.name} bought {coursename}.\\n\") # Prints a confirmation that the course has been purchased\n",
550+
" def buy(self, course_name: str): # Method to assign a course to a student\n",
551+
" Student.users_course[self.name] = course_name # Maps the course name to the student in `users_course`\n",
552+
" print(f\"{self.name} bought {course_name}.\\n\") # Prints a confirmation that the course has been purchased\n",
553553
"\n",
554554
"# Create an object of the class\n",
555-
"obj1 = Student(\"Stud1\", \"Stud1@.com\", \"2547\", True) # Creates an instance `Stud1`\n",
555+
"obj1 = Student(\"Stud1\", \"Stud1@.com\", 2547, True) # Creates an instance `Stud1`\n",
556556
"obj1.buy(\"matlab\") # `Stud1` buys the course \"matlab\"\n",
557-
"obj2 = Student(\"Stud2\", \"Stud2@.com\", \"247\", True) # Creates another instance `Stud2`\n",
557+
"obj2 = Student(\"Stud2\", \"Stud2@.com\", 247, True) # Creates another instance `Stud2`\n",
558558
"obj2.buy(\"python\") # `Stud2` buys the course \"python\"\n",
559-
"obj3 = Student(\"Stud3\", \"Stud3@.com\", \"5478\", True) # Creates another instance `Stud3`\n",
559+
"obj3 = Student(\"Stud3\", \"Stud3@.com\", 5478, True) # Creates another instance `Stud3`\n",
560560
"obj3.login(\"Stud3\") # Attempts to log in the student \"Stud3\"\n",
561561
"\n",
562562
"# Student users & courses\n",
563-
"print(Fore.GREEN + f\"{Student.users = }\\n{Student.users_course = }\")"
563+
"print(Fore.GREEN + f\"{Student.users = }\\n{Student.users_course = }\")\n"
564564
]
565565
},
566566
{
567567
"cell_type": "code",
568-
"execution_count": 13,
568+
"execution_count": null,
569569
"metadata": {},
570570
"outputs": [
571571
{
@@ -581,11 +581,11 @@
581581
}
582582
],
583583
"source": [
584-
"# Remove student users & courseses\n",
584+
"# Remove student users & courses\n",
585585
"obj1.remove_user() # Calls the method to remove `student_jame` from users\n",
586586
"print(Fore.BLUE + f\"{Student.users = }; {Student.users_course = }\")\n",
587587
"\n",
588-
"print(Fore.MAGENTA + f\"{obj1.__dict__ = }\")"
588+
"print(Fore.MAGENTA + f\"{obj1.__dict__ = }\")\n"
589589
]
590590
}
591591
],

0 commit comments

Comments
 (0)