go6odn28

Fund_lab_Zoo

Feb 25th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. class Zoo:
  2.     __animals = 0
  3.  
  4.     def __init__(self, name):
  5.         self.name = name
  6.         self.mammals = []
  7.         self.fishes = []
  8.         self.birds = []
  9.  
  10.     def add_animals(self, species, name):
  11.         if species == "mammal":
  12.             self.mammals.append(name)
  13.         elif species == "fish":
  14.             self.fishes.append(name)
  15.         elif species == "bird":
  16.             self.birds.append(name)
  17.         self.__animals += 1
  18.  
  19.     def get_info(self, species):
  20.         result = ''
  21.         if species == 'mammal':
  22.             result += f"Mammals in {self.name}: {', '.join(self.mammals)}\n"
  23.         elif species == 'fish':
  24.             result += f"Fishes in {self.name}: {', '.join(self.fishes)}\n"
  25.         elif species == 'bird':
  26.             result += f"Birds in {self.name}: {', '.join(self.birds)}\n"
  27.  
  28.         result += f"Total animals: {self.__animals}"
  29.         return result
  30.  
  31.  
  32. zoo_name = input()
  33. zoo = Zoo(zoo_name)
  34. count = int(input())
  35.  
  36. for _ in range(count):
  37.     animal = input().split(" ")
  38.     species, name = animal[0], animal[1]
  39.     zoo.add_animals(species, name)
  40.  
  41.  
  42. info = input()
  43. print(zoo.get_info(info))
  44.  
Add Comment
Please, Sign In to add comment