Skip to content

Commit

Permalink
Merge pull request #58 from nashville-software-school/bn-orientation-…
Browse files Browse the repository at this point in the history
…edits

Bn orientation edits
  • Loading branch information
BryanNilsen authored Jul 20, 2020
2 parents a6f3f4c + 3e62d8c commit 4d4c4a5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
10 changes: 4 additions & 6 deletions book-1-orientation/chapters/CLASSES_07-MULTIPLE_INHERITANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"?

Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions book-1-orientation/chapters/CLASSES_08-DUCK_TYPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.')
```
Expand Down
4 changes: 2 additions & 2 deletions book-1-orientation/chapters/TRY_CATCH_INTRO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down

0 comments on commit 4d4c4a5

Please sign in to comment.