aneliabogeva

Manking

Jul 31st, 2019
124
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Human:
  2. def __init__(self, first_name, last_name):
  3. self.first_name = first_name
  4. self.last_name = last_name
  5.  
  6. @property
  7. def first_name(self):
  8. return self._first_name
  9.  
  10. @property
  11. def last_name(self):
  12. return self._last_name
  13.  
  14. @first_name.setter
  15. def first_name(self, first_name):
  16. first_letter = first_name[0]
  17. if ord(first_letter) not in range(65,90):
  18. raise Exception("Expected upper case letter! Argument: firstName")
  19. if len(first_name) < 4:
  20. raise Exception("Expected length at least 4 symbols! Argument: firstName")
  21. else:
  22. self._first_name = first_name
  23.  
  24. @last_name.setter
  25. def last_name(self, last_name):
  26. first_letter = last_name[0]
  27. if ord(first_letter) not in range(65, 90):
  28. raise Exception("Expected upper case letter! Argument: lastName")
  29. if len(last_name) < 3:
  30. raise Exception("Expected length at least 3 symbols! Argument: lastName ")
  31. else:
  32. self._last_name = last_name
  33.  
  34.  
  35. class Student(Human):
  36. def __init__(self, first_name, last_name, fac_number: str):
  37. Human.__init__(self, first_name, last_name)
  38. self.fac_number = fac_number
  39.  
  40. @property
  41. def fac_number(self):
  42. return self._fac_number
  43.  
  44. @fac_number.setter
  45. def fac_number(self, fac_number):
  46. if len(fac_number) not in range(5,10):
  47. raise Exception("Invalid faculty number!")
  48. else:
  49. self._fac_number = fac_number
  50.  
  51. def __str__(self):
  52. return f"First Name: {self.first_name}\nLast Name: {self.last_name}\nFaculty number: {self.fac_number}"
  53.  
  54. class Worker(Human):
  55. def __init__(self, first_name, last_name, week_salary : float, works_hours :float):
  56. Human.__init__(self, first_name, last_name)
  57. self.week_salary = week_salary
  58. self.works_hours = works_hours
  59.  
  60. def __str__(self):
  61. return f"First Name: {self.first_name}\nLast Name: {self.last_name}\nWeek Salary: {self.week_salary:.2f}\nHours per day: {self.works_hours:.2f}\nSalary per hour: {((self.week_salary / 5)/self.works_hours):.2f}"
  62.  
  63. @property
  64. def week_salary(self):
  65. return self._week_salary
  66.  
  67. @property
  68. def works_hours(self):
  69. return self._works_hours
  70.  
  71. @week_salary.setter
  72. def week_salary(self, week_salary):
  73. if week_salary < 10:
  74. raise Exception("Expected value mismatch! Argument: weekSalary")
  75. else:
  76. self._week_salary = week_salary
  77.  
  78.  
  79. @works_hours.setter
  80. def works_hours(self, works_hours):
  81. if works_hours < 1 or works_hours > 12:
  82. raise Exception("Expected value mismatch! Argument: workHoursPerDay")
  83. else:
  84. self._works_hours = works_hours
  85.  
  86.  
  87. command = input().split()
  88. command_len = len(command)
  89. second_command = input().split()
  90. second_command_len = len(second_command)
  91.  
  92. try:
  93. if command_len == 3:
  94. first_name = command[0]
  95. last_name = command[1]
  96. fac_num = command[2]
  97. person = Student(first_name, last_name, fac_num)
  98. else:
  99. first_name = command[0]
  100. last_name = command[1]
  101. week_salary = float(command[2])
  102. works_hours = float(command[3])
  103. person = Worker(first_name, last_name, week_salary, works_hours)
  104. if second_command_len == 3:
  105. first_name = second_command[0]
  106. last_name = second_command[1]
  107. fac_num = second_command[2]
  108. person2 = Student(first_name, last_name, fac_num)
  109. else:
  110. first_name = second_command[0]
  111. last_name = second_command[1]
  112. week_salary = float(second_command[2])
  113. works_hours = float(second_command[3])
  114. person2 = Worker(first_name, last_name, week_salary, works_hours)
  115. print(person)
  116. print()
  117. print(person2)
  118. except Exception as e:
  119. 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.

×