aneliabogeva

Person

Jul 30th, 2019
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Person:
  2. def __init__(self, name: str, age: int):
  3. self.name = name
  4. self.age = age
  5.  
  6. @property
  7. def age(self):
  8. return self.__age
  9.  
  10. @age.setter
  11. def age(self, value):
  12. if value < 0:
  13. raise Exception("Age must be positive!")
  14. else:
  15. self.__age = value
  16.  
  17. @property
  18. def name(self):
  19. return self.__name
  20.  
  21. @name.setter
  22. def name(self, value):
  23. if len(value) < 3:
  24. raise Exception("Name's length should not be less than 3 symbols!")
  25. else:
  26. self.__name = value
  27.  
  28. def __str__(self):
  29. raise Exception(f"Name: {self.name}, Age: {self.age}")
  30.  
  31. class Child(Person):
  32. def __init__(self, name, age):
  33. Person.__init__(self,name,age)
  34.  
  35. @property
  36. def age(self):
  37. return self.__age
  38.  
  39. @age.setter
  40. def age(self, value):
  41. if value > 15:
  42. raise Exception("Child's age must be less than 15!")
  43. if value < 0:
  44. raise Exception("Age must be positive!")
  45. else:
  46. self.__age = value
  47.  
  48.  
  49. name = input()
  50. age = int(input())
  51. try:
  52. chld = Child(name, age)
  53. print(chld.__str__())
  54. except Exception as e:
  55. 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.

×