Advertisement
Radoslav_03

2_zad_employee.py

Sep 17th, 2023
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.98 KB | None | 0 0
  1. class Employee:
  2.     def __init__(self, i_num, fname, lname, work_experience, education_level, salary, age):
  3.         self.i_num = i_num
  4.         self.fname = fname
  5.         self.lname = lname
  6.         self.work_experience = work_experience
  7.         self.education_level = education_level
  8.         self.salary = salary
  9.         self.age = age
  10.  
  11.     def display_info(self):
  12.         print(f"Служебен номер: {self.i_num}")
  13.         print(f"Име: {self.fname}")
  14.         print(f"Фамилия: {self.lname}")
  15.         print(f"Трудов стаж: {self.work_experience} години")
  16.         print(f"Образование: {self.education_level}")
  17.         print(f"Заплата: {self.salary} BGN")
  18.         print(f"Възраст: {self.age} години")
  19.  
  20.     def bonus(self):
  21.         bonus_percent = 0
  22.         if self.education_level == "висше":
  23.             bonus_percent += 5
  24.         if self.education_level == "средно":
  25.             bonus_percent += 2
  26.  
  27.         bonus_percent += 1.2 * self.work_experience
  28.  
  29.         return self.salary * (bonus_percent / 100)
  30.  
  31. def sort_employee(employee_list):
  32.     sorted_employees = sorted(employee_list, key=lambda x: x.age)
  33.     for employee in sorted_employees:
  34.         employee.display_info()
  35.  
  36. def search_by_name(employee_list, name, lname):
  37.     found = False
  38.     for employee in employee_list:
  39.         if employee.fname == name and employee.lname == lname:
  40.             employee.display_info()
  41.             found = True
  42.             break
  43.  
  44.     if not found:
  45.         print("Not found!!!")
  46.  
  47. def print_by_education_experience(employee_list, education, experience):
  48.     for employee in employee_list:
  49.         if employee.education_level == education and employee.work_experience == experience:
  50.             employee.display_info()
  51.  
  52. def remove_employee(employee_list, i_num):
  53.     for employee in employee_list:
  54.         if employee.i_num == i_num:
  55.             employee_list.remove(employee)
  56.             print("Information deleted !!!")
  57.             break
  58.     else:
  59.         print("Wrong i_num !!!")
  60.  
  61. employee_list = []
  62.  
  63. n = int(input("Въведете брой служители: "))
  64.  
  65. for _ in range(n):
  66.     i_num = input("Служебен номер: ")
  67.     fname = input("Име: ")
  68.     Iname = input("Фамилия: ")
  69.     work_experience = int(input("Трудов стаж (години): "))
  70.     education_level = input("Образование (основно, средно, висше): ")
  71.     salary = float(input("Заплата: "))
  72.     age = int(input("Възраст: "))
  73.  
  74.     employee = Employee(i_num, fname, Iname, work_experience, education_level, salary, age)
  75.     employee_list.append(employee)
  76.  
  77. while True:
  78.     print("\nМеню:")
  79.     print("1. Сортиране на служителите по възраст")
  80.     print("2. Търсене на служител по име и фамилия")
  81.     print("3. Извеждане на служители по образование и стаж")
  82.     print("4. Изтриване на служител по служебен номер")
  83.     print("5. Изход")
  84.  
  85.     choice = int(input("Изберете опция: "))
  86.  
  87.     match choice:
  88.         case 1:
  89.             sort_employee(employee_list)
  90.         case 2:
  91.             name = input("Въведете име: ")
  92.             Iname = input("Въведете фамилия: ")
  93.             search_by_name(employee_list, name, Iname)
  94.         case 3:
  95.             education = input("Въведете образование: ")
  96.             experience = int(input("Въведете стаж (години): "))
  97.             print_by_education_experience(employee_list, education, experience)
  98.         case 4:
  99.             i_num = input("Въведете служебен номер: ")
  100.             remove_employee(employee_list, i_num)
  101.             print(employee_list)
  102.         case 5:
  103.             break
  104.         case _:
  105.             print("Невалиден избор. Моля, опитайте отново.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement