0
  1. Amend your looking method to create a single string representing the animals and birds in the zoo. Hint: create a static method that accepts the concatenated list of animal list and bird list and uses the reduce and map functions with the lambda function to get the look method for each item in the concatenated list.
  2. Add one method (called find_canine ) into the zoo class to find all the canines in the zoo. This method can use a filter function with lambda function to check if the item object in the animal list has the same instance as Canine and return a list that can pass to the static method built in Point 2 to return a string representation of that object.
  3. Add one method (called find_tiger) into the zoo class to filter out tigers in the zoo and look at them. This method can use a filter function with re.search and map and lambda functions to achieve this functionality. Hint: you will have to go over all the animals in the zoo.
    class Animal():
        def __init__(self):
            self.__number_of_hands=0
            self.__number_of_legs=4
        def look(self):
            return "Number of hands: {hands}, Number of legs: {legs}".format(hands = self.__number_of_hands, legs = self.__number_of_legs)
    class Feline(Animal):
        def __init__(self):
            Animal.__init__(self)
            self.__characteristic = "Feline belong to the cat family"
        def look(self):
            return super().look() + "\n" + self._characteristic
    class Tiger(Feline):
        def __init__(self):
            Feline.__init__(self)
            self._characteristic = "Tigers can roar and are lethal predators"
        def look(self):
            return super().look() + "\n" + self._characteristic
    
    class Wild_Cat(Feline):
        def __init__(self):
            Feline.__init__(self)
            self._characteristic = "Wild cats can climb trees"
        def look(self):
            return super().look() + "\n" + self._characteristic
    
    class Canine(Animal):
        def __init__(self):
            Animal.__init__(self)
            self._characteristic = "Canines belong to the dog family"
        def look(self):
            return super().look() + self._characteristic
    
    class Wolf(Canine):
        def __init__(self):
            Canine.__init__(self)
            self._characteristic = "Wolves hunt in packs and have a leader"
        def look(self):
            return super().look() + "\n" + self._characteristic
    
    class Bird():
        def __init__(self):
            self._number_of_legs = 2
            self._number_of_wings = 2
        def look(self):
            return "Number of legs: {legs}, Number of wings: {wings}".format(legs = self._number_of_legs, wings = self._number_of_wings)
    class Flight_Bird(Bird):
        def __init__(self):
            Bird.__init__(self)
            self._characteristic = "Flight birds fly and hunt for food"
        def look(self):
            return super().look() + "\n" +  self._characteristic
    class Eagle(Flight_Bird):
        def __init__(self):
            Flight_Bird.__init__(self)
            self._characteristic = "Eagles fly extremely high and can see their prey from high up in the sky"
        def look(self):
            return super().look() + "\n" + self._characteristic

 # Part 2
 
class Zoo():

    def __init__(self):
        self._animals = []
        self._birds = []
    def add(self,animal):
        if isinstance(animal, Bird):
            if len(self._birds) < 1:
                self._birds.append(animal)
                print("Added bird to the zoo.")
            else:
                print("Zoo full for birds.")
        elif isinstance(animal, Animal):
            if len(self._animals) < 2:
                self._animals.append(animal)
                print("Added animal to the zoo.")
            else:
                print("Zoo full for animals")
        else:
            print("Invalid input.Cannot add to the zoo.")

    def looking(self):
        for animal in self._animals:
            print()
            print(animal.look())
        for bird in self._birds:
            print()
            print(bird.look())

I try to add all methods but it didn't work.

  • Please add more details like what are you trying to do. – Avinash Dalvi Apr 30 '23 at 15:04
  • What do you mean by "it didn't work"? This looks like a course assignment, which you should really be doing yourself. Seems similar to: [python - regex to search a list of class objects - Stack Overflow](https://stackoverflow.com/questions/74493235/regex-to-search-a-list-of-class-objects) – John Rotenstein Apr 30 '23 at 23:00

0 Answers0