|
58 | 58 | }, |
59 | 59 | { |
60 | 60 | "cell_type": "code", |
61 | | - "execution_count": 1, |
| 61 | + "execution_count": null, |
62 | 62 | "metadata": {}, |
63 | 63 | "outputs": [], |
64 | 64 | "source": [ |
65 | | - "from colorama import Fore " |
| 65 | + "from colorama import Fore \n" |
66 | 66 | ] |
67 | 67 | }, |
68 | 68 | { |
|
112 | 112 | }, |
113 | 113 | { |
114 | 114 | "cell_type": "code", |
115 | | - "execution_count": 2, |
| 115 | + "execution_count": null, |
116 | 116 | "metadata": {}, |
117 | 117 | "outputs": [ |
118 | 118 | { |
|
148 | 148 | "print(Fore.GREEN + f\"{obj2.name = :5} {obj2.lname = :5} {obj2.age = }\")\n", |
149 | 149 | "\n", |
150 | 150 | "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" |
152 | 152 | ] |
153 | 153 | }, |
154 | 154 | { |
|
174 | 174 | }, |
175 | 175 | { |
176 | 176 | "cell_type": "code", |
177 | | - "execution_count": 3, |
| 177 | + "execution_count": null, |
178 | 178 | "metadata": {}, |
179 | 179 | "outputs": [ |
180 | 180 | { |
|
208 | 208 | "\n", |
209 | 209 | "print(Fore.BLUE + f\"\\n{55 * \"=\"} Dict {54 * \"=\"}\")\n", |
210 | 210 | "print(f\"{obj1.__dict__ = }\")\n", |
211 | | - "print(f\"{obj2.__dict__ = }\")" |
| 211 | + "print(f\"{obj2.__dict__ = }\")\n" |
212 | 212 | ] |
213 | 213 | }, |
214 | 214 | { |
|
231 | 231 | }, |
232 | 232 | { |
233 | 233 | "cell_type": "code", |
234 | | - "execution_count": 4, |
| 234 | + "execution_count": null, |
235 | 235 | "metadata": {}, |
236 | 236 | "outputs": [ |
237 | 237 | { |
|
264 | 264 | "\n", |
265 | 265 | "# ----------------- Access attributes & print the name, lname, age, and pay of each object ---------------------\n", |
266 | 266 | "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" |
268 | 268 | ] |
269 | 269 | }, |
270 | 270 | { |
271 | 271 | "cell_type": "code", |
272 | | - "execution_count": 5, |
| 272 | + "execution_count": null, |
273 | 273 | "metadata": {}, |
274 | 274 | "outputs": [ |
275 | 275 | { |
|
290 | 290 | "obj2.pay_increase() # Call method to increase pay for object2\n", |
291 | 291 | "\n", |
292 | 292 | "# Print the updated pay values for both objects\n", |
293 | | - "print(f\"{obj1.pay = }, {obj2.pay = }\")" |
| 293 | + "print(f\"{obj1.pay = }, {obj2.pay = }\")\n" |
294 | 294 | ] |
295 | 295 | }, |
296 | 296 | { |
297 | 297 | "cell_type": "code", |
298 | | - "execution_count": 6, |
| 298 | + "execution_count": null, |
299 | 299 | "metadata": {}, |
300 | 300 | "outputs": [ |
301 | 301 | { |
|
319 | 319 | "obj2.pay_increase() # Increases pay for object2 with the original class variable value\n", |
320 | 320 | "\n", |
321 | 321 | "# 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" |
323 | 323 | ] |
324 | 324 | }, |
325 | 325 | { |
326 | 326 | "cell_type": "code", |
327 | | - "execution_count": 7, |
| 327 | + "execution_count": null, |
328 | 328 | "metadata": {}, |
329 | 329 | "outputs": [ |
330 | 330 | { |
|
339 | 339 | ], |
340 | 340 | "source": [ |
341 | 341 | "# 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" |
343 | 343 | ] |
344 | 344 | }, |
345 | 345 | { |
|
370 | 370 | }, |
371 | 371 | { |
372 | 372 | "cell_type": "code", |
373 | | - "execution_count": 8, |
| 373 | + "execution_count": null, |
374 | 374 | "metadata": {}, |
375 | 375 | "outputs": [ |
376 | 376 | { |
|
393 | 393 | " users = [] # Class variable to store list of user names\n", |
394 | 394 | " users_course = {} # Class variable to store dictionary mapping user names to their courses\n", |
395 | 395 | " \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", |
397 | 397 | " self.name = name # Instance variable to store the student's name\n", |
398 | 398 | " self.email = email # Instance variable to store the student's email\n", |
399 | 399 | " self.password = password # Instance variable to store the student's password\n", |
|
407 | 407 | " else:\n", |
408 | 408 | " print(f\"{name} must register.\") # Indicates the user must register\n", |
409 | 409 | " \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", |
413 | 413 | "\n", |
414 | 414 | "# 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", |
416 | 416 | "obj1.buy(\"matlab\") # The student \"aa\" purchases the \"matlab\" course\n", |
417 | 417 | "\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" |
420 | 420 | ] |
421 | 421 | }, |
422 | 422 | { |
423 | 423 | "cell_type": "code", |
424 | | - "execution_count": 9, |
| 424 | + "execution_count": null, |
425 | 425 | "metadata": {}, |
426 | 426 | "outputs": [ |
427 | 427 | { |
|
435 | 435 | ], |
436 | 436 | "source": [ |
437 | 437 | "# Student users & courses\n", |
438 | | - "print(f\"{Student.users = }\\n{Student.users_course = }\")" |
| 438 | + "print(f\"{Student.users = }\\n{Student.users_course = }\")\n" |
439 | 439 | ] |
440 | 440 | }, |
441 | 441 | { |
442 | 442 | "cell_type": "code", |
443 | | - "execution_count": 10, |
| 443 | + "execution_count": null, |
444 | 444 | "metadata": {}, |
445 | 445 | "outputs": [ |
446 | 446 | { |
|
457 | 457 | "source": [ |
458 | 458 | "# Update student users & courses\n", |
459 | 459 | "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", |
461 | 461 | "obj3.login(\"Stud3\") # Now attempts to log in \"Stud3\" again, expected print: \"Stud3 has an account.\"\n", |
462 | 462 | "print(Fore.MAGENTA + f\"{Student.users = }; {Student.users_course = }\") # Prints the updated list of user names, courese\n" |
463 | 463 | ] |
464 | 464 | }, |
465 | 465 | { |
466 | 466 | "cell_type": "code", |
467 | | - "execution_count": 11, |
| 467 | + "execution_count": null, |
468 | 468 | "metadata": {}, |
469 | 469 | "outputs": [ |
470 | 470 | { |
|
478 | 478 | } |
479 | 479 | ], |
480 | 480 | "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" |
482 | 482 | ] |
483 | 483 | }, |
484 | 484 | { |
|
495 | 495 | }, |
496 | 496 | { |
497 | 497 | "cell_type": "code", |
498 | | - "execution_count": 12, |
| 498 | + "execution_count": null, |
499 | 499 | "metadata": {}, |
500 | 500 | "outputs": [ |
501 | 501 | { |
|
523 | 523 | " users = [] # Class variable that keeps a list of user names\n", |
524 | 524 | " users_course = {} # Class variable that maps user names to their purchased courses\n", |
525 | 525 | " \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", |
527 | 527 | " self.name = name # Instance variable for storing the student's name\n", |
528 | 528 | " self.email = email # Instance variable for storing the student's email\n", |
529 | 529 | " self.password = password # Instance variable for storing the student's password\n", |
|
547 | 547 | " else:\n", |
548 | 548 | " print(f\"{name} must register.\\n\") # Message indicating the user needs to register\n", |
549 | 549 | " \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", |
553 | 553 | "\n", |
554 | 554 | "# 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", |
556 | 556 | "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", |
558 | 558 | "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", |
560 | 560 | "obj3.login(\"Stud3\") # Attempts to log in the student \"Stud3\"\n", |
561 | 561 | "\n", |
562 | 562 | "# 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" |
564 | 564 | ] |
565 | 565 | }, |
566 | 566 | { |
567 | 567 | "cell_type": "code", |
568 | | - "execution_count": 13, |
| 568 | + "execution_count": null, |
569 | 569 | "metadata": {}, |
570 | 570 | "outputs": [ |
571 | 571 | { |
|
581 | 581 | } |
582 | 582 | ], |
583 | 583 | "source": [ |
584 | | - "# Remove student users & courseses\n", |
| 584 | + "# Remove student users & courses\n", |
585 | 585 | "obj1.remove_user() # Calls the method to remove `student_jame` from users\n", |
586 | 586 | "print(Fore.BLUE + f\"{Student.users = }; {Student.users_course = }\")\n", |
587 | 587 | "\n", |
588 | | - "print(Fore.MAGENTA + f\"{obj1.__dict__ = }\")" |
| 588 | + "print(Fore.MAGENTA + f\"{obj1.__dict__ = }\")\n" |
589 | 589 | ] |
590 | 590 | } |
591 | 591 | ], |
|
0 commit comments