class Employee:
def __init__(self, name, position=None, salary=0):
if isinstance(salary, (int, float)):
self.name = name
self.position = position
self.salary = round(salary, 2)
else:
raise TypeError("Salary must be an int or float")
def raise_salary(self, percentage):
if isinstance(percentage, (int, float)):
self.salary += round(self.salary * percentage, 2)
else:
raise TypeError("Percentage must be an int or float")
def __str__(self):
return f"Name: {self.name}\nPosition: {self.position}\nSalary: {self.salary}"
class Manager(Employee):
def __init__(self, name, position=None, salary=0, bonus_percentage=0):
super().__init__(name, position, salary)
self.bonus_percentage = bonus_percentage
def raise_salary(self, percentage):
super().raise_salary(percentage)
self.salary += round(self.salary * self.bonus_percentage, 2)
def __str__(self):
return f"Name: {self.name}\nPosition: {self.position}\nSalary: {self.salary}\nBonus Percentage: {self.bonus_percentage}"
positions = ["Developer", "Manager", "Team Lead", "HR", "Designer"]
salary_dict = {
"Developer": 50000,
"Manager": 60000,
"Team Lead": 70000,
"HR": 45000,
"Designer": 55000
}
class EmployeeWithPosition(Employee):
def __init__(self, name, position_index):
position = positions[position_index]
salary = salary_dict[position]
super().__init__(name, position, salary)
def display_employee_info(employee, raise_percentage, bonus_percentage=0):
print(employee)
if isinstance(employee, Manager):
employee.raise_salary(raise_percentage)
employee.bonus_percentage = bonus_percentage
else:
employee.raise_salary(raise_percentage)
print("\nUpdated Info:")
print(employee)
# Пример использования:
sergey = Manager("Sergey", 1, 60000, 0.1) # Менеджер с бонусом 10%
display_employee_info(sergey, 0.3, 0.05)
# Создание сотрудника с должностью из списка
employee = EmployeeWithPosition("Alex", 2) # Team Lead
print("\nNew Employee:")
print(employee)