修改类以包含以下功能

问题描述 投票:0回答:0
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

第二部分

类动物园():

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())

我尝试添加所有方法,但没有用

exception aws-lambda lambda reduce isinstance
© www.soinside.com 2019 - 2024. All rights reserved.