Created
February 7, 2019 11:08
-
-
Save martin-martin/5395d3dd3a06ad60acc84d6da6cc1673 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # CLASSES AND OBJECT-ORIENTED PROGRAMMING | |
| class Ingredient: | |
| """Models an ingredient including its name and amount.""" | |
| def __init__(self, name, amount): | |
| self.name = name | |
| self.amount = amount | |
| def __str__(self): | |
| return f"There are {self.amount} of {self.name}." | |
| def use(self, use_amount): | |
| """Reduces the amount of ingredient available.""" | |
| self.amount -= use_amount | |
| def expire(self): | |
| """Expires the ingredient item.""" | |
| print(f"whoops, these {self.name} went bad...") | |
| self.name = "expired " + self.name | |
| # INHERITANCE | |
| # build a subclass called Spice | |
| # create a custom method grind() | |
| # override the expire() method | |
| # customize the __init__() method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment