aneliabogeva

Animals

Jul 16th, 2019
5,890
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from abc import ABC, abstractmethod
  2.  
  3. class Animal(ABC):
  4. def __init__(self,typee: str, name: str, age: int, gender: str):
  5. self.name = name
  6. self.age = age
  7. self.gender = gender
  8. self.typee = typee
  9.  
  10. @abstractmethod
  11. def Produce_sound(self):
  12. pass
  13.  
  14. @property
  15. def age(self):
  16. return self._age
  17.  
  18. @age.setter
  19. def age(self, age):
  20. if age < 0:
  21. raise Exception("Invalid input!")
  22. else:
  23. self._age = age
  24.  
  25. @property
  26. def gender(self):
  27. return self._gender
  28.  
  29. @gender.setter
  30. def gender(self, gender):
  31. if not (gender == "Male" or gender == "Female"):
  32. raise Exception("Invalid input!")
  33. else:
  34. self._gender = gender
  35.  
  36. def __str__(self):
  37. return f"{self.typee}\n{self.name} {self.age} {self.gender}\n{self.Produce_sound()}"
  38.  
  39. class Dog(Animal):
  40. def Produce_sound(self):
  41. return "Woof!"
  42.  
  43. def __init__(self,typee, name, age, gender):
  44. Animal.__init__(self,typee, name, age, gender)
  45.  
  46.  
  47. class Frog(Animal):
  48. def Produce_sound(self):
  49. return "Ribbit"
  50.  
  51. def __init__(self, typee, name, age, gender):
  52. Animal.__init__(self, typee, name, age, gender)
  53.  
  54.  
  55. class Cat(Animal):
  56. def Produce_sound(self):
  57. return "Meow meow"
  58.  
  59. def __init__(self,typee, name, age, gender):
  60. Animal.__init__(self, typee, name, age, gender)
  61.  
  62. class Tomcat(Animal):
  63. def Produce_sound(self):
  64. return "MEOW"
  65.  
  66. def __init__(self, typee, name, age, gender = 'Male'):
  67. Animal.__init__(self,typee, name, age, gender)
  68.  
  69. class Kitten(Animal):
  70. def Produce_sound(self):
  71. return "Meow"
  72.  
  73. def __init__(self,typee, name, age, gender = 'Female'):
  74. Animal.__init__(self,typee, name, age, gender)
  75.  
  76.  
  77. animals_list = []
  78. animal_type = input()
  79.  
  80. while not animal_type == "Beast!":
  81. typee = animal_type
  82. name, age, gender = input().split()
  83. if not (animal_type == "Dog" or animal_type == "Cat" or animal_type == "Frog" or animal_type == "Tomcat" or animal_type == "Kitten"):
  84. print("Invalid input!")
  85. else:
  86. if int(age) <= 0:
  87. print("Invalid input!")
  88. else:
  89. if not (typee == "Tomcat" or typee == "Kitten"):
  90. str_class_instance = f"{animal_type}('{typee}','{name}',{age},'{gender}')"
  91. current_animal = eval(str_class_instance)
  92. else:
  93. str_class_instance = f"{animal_type}('{typee}','{name}',{age})"
  94. current_animal = eval(str_class_instance)
  95. animals_list.append(current_animal)
  96. animal_type = input()
  97. try:
  98. for animal in animals_list:
  99. print(animal)
  100. except Exception as e:
  101. print(str(e))
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×