<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Zoo
# Economics
# Facility -&gt; Cage, Restaurant
# People -&gt; Visitor, Employee
# Animal -&gt; DangerousAnimal, WaterAnimal -&gt; ...

class Animal():
    """Representation of an animal."""
    def __init__(self, species, gender):
        self.species = species
        self.gender = gender

    def __str__(self):
        return f"{self.species} ({self.gender})"
        # print("{0} ({1})".format(self.species, self.gender))

class Facility():
    """Representation of a zoo facility."""
    def __init__(self, area):
        """
        :param area: Number of sqm a facility requires.
        """
        self.area = area

class Cage(Facility):
    """Representation of a cage."""
    def __init__(self, area, animals=None):
        """
        :param animals: The animals inside this cage.
        """
        Facility.__init__(self, area)
        if animals is None:
            self.animals = []

class Restaurant(Facility):
    """Representation of a restaurant."""
    def __init__(self, area, customers=None):
        """

        :param area: The area of the facility in sqm.
        :param customers: The customers of this restaurant.
        """
        Facility.__init__(area)
        if customers is None:
            self.customers = []

class Zoo():
    def __init__(self):
        self.animals = []
        self.restaurants = []
        self.cages = []
        self.facilities = []

    def add_animal(self, animal):
        """Add an animal to the zoo.

        :param animal: Animal to add.
        :return:
        """
        self.animals.append(animal)

    def num_animals(self):
        """Returns the number of animals.

        :return: The number of animals.
        """
        return len(self.animals)

    def add_restaurant(self, restaurant):
        self.restaurants.append(restaurant)
        self.facilities.append(restaurant)

    def add_cage(self, cage):
        self.cages.append(cage)
        self.facilities.append(cage)


    def assign_animals(self):
        """Redistribute all the animals of the zoo to cages without mixing the species.

        :return: True if successful, false if not.
        """
        species = set()
        for animal in self.animals:
            species.add(animal.species)

        if len(species) &gt; len(self.cages):
            return False

        species_cage_dict = {}
        counter = 0
        for animal in self.animals:
            if animal.species in species_cage_dict:
                species_cage_dict[animal.species].animals.append(animal)
            else:
                species_cage_dict[animal.species] = self.cages[counter]
                counter += 1
                species_cage_dict[animal.species].animals.append(animal)



if __name__ == "__main__":
    my_zoo = Zoo()

    elephant_1 = Animal('Elephant', 'Male')
    my_zoo.add_animal(elephant_1)
    my_zoo.add_animal(Animal('Elephant', 'Male'))
    my_zoo.add_animal(Animal('Giraffe', 'Male'))
    my_zoo.add_animal(Animal('Lion', 'Female'))
    my_zoo.add_animal(Animal('Lion', 'Female'))
    my_zoo.add_animal(Animal('Lion', 'Female'))
    my_zoo.add_animal(Animal('Zebra', 'Female'))

    my_zoo.add_cage(Cage(500))
    my_zoo.add_cage(Cage(500))
    my_zoo.add_cage(Cage(500))
    my_zoo.add_cage(Cage(500))
    my_zoo.add_cage(Cage(500))

    my_zoo.assign_animals()

    print('stop')</pre></body></html>