Skip to content

Instantly share code, notes, and snippets.

@martin-martin
Created February 7, 2019 11:08
Show Gist options
  • Select an option

  • Save martin-martin/5395d3dd3a06ad60acc84d6da6cc1673 to your computer and use it in GitHub Desktop.

Select an option

Save martin-martin/5395d3dd3a06ad60acc84d6da6cc1673 to your computer and use it in GitHub Desktop.
# 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