diff --git a/book-1-orientation/chapters/CLASSES_07-MULTIPLE_INHERITANCE.md b/book-1-orientation/chapters/CLASSES_07-MULTIPLE_INHERITANCE.md index 89a0951c..91e4ed3f 100644 --- a/book-1-orientation/chapters/CLASSES_07-MULTIPLE_INHERITANCE.md +++ b/book-1-orientation/chapters/CLASSES_07-MULTIPLE_INHERITANCE.md @@ -39,7 +39,7 @@ petting_zoo/ |__ goose.py # another critter class. you get the point |__ attractions/ |__ __init__.py - |__ atttraction.py + |__ attraction.py |__ petting_zoo.py |__ snake_pit.py |__ wetlands.py @@ -113,6 +113,7 @@ Now you can define a class and implement multiple inheritance for a walking and ```py # The package syntax is what allows for these clean import statements +from .animal import Animal from movements import Walking, Swimming class Goose(Animal, Walking, Swimming): @@ -197,7 +198,7 @@ The animal swims Now each class can override and specialize inherited behavior, or simply choose to let the parent class' logic run, depending on the situation. -## Pracice: More Attractive Attractions +## Practice: More Attractive Attractions Your critter types are in much better shape, so it's time to overhaul the attractions, too, and apply some inheritance magic to them. After all, what happens when Bobby announces he's adding a "Monkey Island" or "Big Kat Kountry"? @@ -240,9 +241,6 @@ class PettingZoo(Attraction): def __init__(self, name, description): super().__init__(name, description) - - def addAnimal(self, animal): - self.animals.append(animal) ``` Don't forget to add the module imports to the attractions package. @@ -268,7 +266,7 @@ from petting_zoo import PettingZoo bob = Goose("Bob", "Canada goose", "watercress sandwiches") # Create an attraction -varmint_village = PettingZoo("Varmint Village") +varmint_village = PettingZoo("Varmint Village", "critters that like to dig and scurry") varmint_village.add_animal(bob) for animal in varmint_village.animals: diff --git a/book-1-orientation/chapters/CLASSES_08-DUCK_TYPING.md b/book-1-orientation/chapters/CLASSES_08-DUCK_TYPING.md index 09b41b01..86cd8948 100644 --- a/book-1-orientation/chapters/CLASSES_08-DUCK_TYPING.md +++ b/book-1-orientation/chapters/CLASSES_08-DUCK_TYPING.md @@ -4,7 +4,7 @@ > >In Python, lists can contain any combination of object types. A single list could contain an integer, a boolean, and a string. This means that the `animals` attribute of your attractions classes can contain **any** critter type, regardless of whether it belongs there. > ->You decide that you'll need to add a check to the `addAnimal` method of your attractions classes to make sure a critter belongs in the attraction you're adding it to. Luckily, you already have a built-in way of determining what kind of critter you're dealing with... +>You decide that you'll need to add a check to the `add_animal` method of your attractions classes to make sure a critter belongs in the attraction you're adding it to. Luckily, you already have a built-in way of determining what kind of critter you're dealing with... ### Using Your Inherited Class Properties to Restrict Lists @@ -32,7 +32,7 @@ class PettingZoo(Attraction): # Number 2: Actual typing check def add_animal_type_check(self, animal): if isinstance(animal, Swimming): - self.animals.add(animal) + self.animals.append(animal) else: print(f'{animal} doesn\'t like to be petted, so please do not try to put it in the {self.name} attraction.') ``` diff --git a/book-1-orientation/chapters/TRY_CATCH_INTRO.md b/book-1-orientation/chapters/TRY_CATCH_INTRO.md index fdea3e96..213bd045 100644 --- a/book-1-orientation/chapters/TRY_CATCH_INTRO.md +++ b/book-1-orientation/chapters/TRY_CATCH_INTRO.md @@ -38,7 +38,7 @@ my_account.add_money(-55) This will raise a `TypeError` exception because the logic for the `add_money()` tries to perform a mathematical calculation on the value that is stored in the `amount` argument. We passed in a string, so Python will yell at us. There is no type coercion in Python. So, in JavaScript "2" + 2 will work, and give you "22", but not so in Python. -So we need to think about these kinds of issues when writing our code instead of assuming the the code that invokes this method will *always* do the correct thing. We need implement exception handling so that a useful exception is raised to the invoking code. +So we need to think about these kinds of issues when writing our code instead of assuming that the code that invokes this method will _always_ do the correct thing. We need implement exception handling so that a useful exception is raised to the invoking code. Let's look at how to do that with `try...except` blocks. @@ -56,7 +56,7 @@ def add_money(self, amount): return self.balance else: raise ArithmeticError("Amount needs to be a positive number") - + except TypeError: print('(Error): The add_money method requires a numeric value') raise