American Young Coder (AYC)

AYC logo
Loading Events

« All Events

  • This event has passed.

5 PM – Python OOP – Darin

December 18, 2023 @ 5:00 pm - 6:00 pm

Today We Did

  1. Learnt the new topic on inheritance, and how it helps reduce code duplication
  2. Finished try it yourself number 9-6, further learning how inheritance works with code, how to use super().__init__(self, …, …) to initialize the attributes of the new class.
  3. Started on the Monster Inheritance project.

Homework

Upload Dec18_Inheritance_HW.py into the google drive when finished. Upload monster.py and monster_system.py into a file called MonsterInheritance on the google drive.

  1. Continue on your file called Dec18_Inheritance_HW.py and finish Try It Yourself – pg.173, 9-7
  2. Start creating the MonsterInheritance Project, and start with 2 files, monster.py and monster_system.py (this is your main file where you run application_loop() ).In monster_system, create the __init__(self, …) method with the following attributes:
    – A dictionary to hold the monsters called monster_dictionary
    – the main menu string called main_menu (it looks like this below):

    Create the application_loop() method that shows the menu (until the user enters exit) and takes in the input (1, 2, or 3), and if any other value is given, it prints out the message as shown below:
    Create the Monster class in a separate file called monster.py and give it the 3 following attributes: species, health, and max_attack. health and max_attack will be integer values. Create a method called get_info that displays the information such as:

    Dragon – 150 Health – 50 Max Attack

    Go back to the MonsterSystem class and create the add_monster() and display_all_monsters() method to use when the user inputs 1 or 2.

    In add_monster(), ask the user for species, health, and max_attack which will be used to initialize a Monster object, which you will put into the dictionary. Use the species name for the dictionary key.

    These are all things you should already be familiar with from library system or the school system project (printing a menu, showing all the items in a dictionary (using a for loop), and adding items to the dictionary.

    This is what the program looks like after the user enters 2 (which calls the display_all_monsters() method in the application_loop() method):

    This is what the program looks like after the user enters 1:

Notes

If you have any questions, email me at ddjapri@ayclogic.com !!

Details

Date:
December 18, 2023
Time:
5:00 pm - 6:00 pm
Event Categories:
,
Verified by MonsterInsights