Skip to content

Instantly share code, notes, and snippets.

@kurzweil777
Created May 27, 2020 07:46
Show Gist options
  • Save kurzweil777/408dbfe3b4c1e322ef8dd108b472446d to your computer and use it in GitHub Desktop.
Save kurzweil777/408dbfe3b4c1e322ef8dd108b472446d to your computer and use it in GitHub Desktop.
First Attempts in OOP
class Animal:
name = ""
category = ""
def __init__(self, name):
self.name = name
def set_category(self, category):
self.category = category
class Zoo:
def __init__(self):
self.current_animals = {}
def add_animal(self, animal):
self.current_animals[animal.name] = animal.category
def total_of_category(self, category):
result = 0
for animal in self.current_animals.values():
if animal == category:
result += 1
return result
Turtle = Animal('Turtle')
Snake = Animal('Snake')
Turtle.set_category('Reptile')
Snake.set_category('Reptile')
zoo = Zoo()
print(Snake.category)
zoo.add_animal(Turtle)
zoo.add_animal(Snake)
print(zoo.total_of_category('Reptile'))
@OurTechGroup
Copy link

Great activity on code reuse! My Zoo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment