Guest User

Untitled

a guest
Dec 5th, 2021
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.74 KB | None | 0 0
  1. class CreditDepartament:                # банк
  2.     def __init__(self, base_rate):
  3.         self.base_rate = base_rate      # базовая ставка
  4.         self.clients = []               # клиенты банка
  5.     def add_client(self, client):       # добавить клиента
  6.         self.clients.append(client)
  7.  
  8.     def credit_decision(self, client):  # решение по кредиту
  9.         for item in self.clients:
  10.             if item == client: # если клиент найден в списке вывод решения
  11.                 return "Выдать кредит: " + client.about() + ". Процентная ставка: " + str(round(self.base_rate + client.personal_rate(),2))
  12.         return "Такого клиента нет"
  13.  
  14.     def credit_decision(self):  # решение по кредиту
  15.         for client in self.clients:
  16.             print("Выдать кредит: " + client.about() + ". Процентная ставка: " + str(round(self.base_rate + client.personal_rate(),2)))
  17.  
  18. class Client:                   # базовый класс клиент
  19.     def __init__(self, name, age, rating):
  20.         self._name = name       # имя
  21.         self._age = age         # возраст
  22.         self._rating = rating   # кредитный рейтинг
  23.  
  24.     def personal_rate(self):    # расчет рейтинга
  25.         return 1.0 / self._rating + 0.01 * self._age
  26.  
  27.     def about(self):            # вывод информации о клиенте
  28.         return "Клиент: " + self._name + " ,Возраст: " + str(self._age) + " лет, Категория:"
  29.  
  30. class Employee(Client):         # наследуемый класс Сотрудник
  31.     def __init__(self, name, age, rating, discount):
  32.         Client.__init__(self, name, age, rating)
  33.         self.discount = discount
  34.    
  35.    
  36.     def about(self):
  37.         return str(Client.about(self)) + str(" Сотрудник")
  38.  
  39.     def personal_rate(self):
  40.         return Client.personal_rate(self) - self.discount * 1.8
  41.  
  42. class Privileges(Client):       # наследуемый класс Льготник
  43.     def __init__(self, name, age, rating, discount):
  44.         Client.__init__(self, name, age, rating)
  45.         self.discount = discount
  46.        
  47.     def about(self):
  48.         return str(Client.about(self)) + str(" Льготник")
  49.  
  50.     def personal_rate(self):
  51.         return Client.personal_rate(self) - self.discount * 1.2
  52.  
  53. class OrdinaryCitizen(Client):      # наследуемый класс Обычный гражданин
  54.     def __init__(self, name, age, rating, discount):
  55.         Client.__init__(self, name, age, rating)
  56.         self.discount = discount
  57.     def about(self):
  58.         return str(Client.about(self)) + str(" Обычный гражданин")
  59.  
  60.     def personal_rate(self):
  61.         return Client.personal_rate(self) + self.discount * 0.1
  62.  
  63. class CitizenBadHistory(Client):    # наследуемый класс Гражданин с плохой информацией
  64.     def __init__(self, name, age, rating, discount):
  65.         Client.__init__(self, name, age, rating)
  66.         self.discount = discount
  67.  
  68.     def about(self):
  69.         return str(Client.about(self)) + str(" Гражданин с плохой историей")
  70.  
  71.     def personal_rate(self):
  72.         return Client.personal_rate(self) + self.discount * 3
  73.  
  74. def print_menu():
  75.     print('1. Добавить сотрудника')
  76.     print('2. Добавить льготника')
  77.     print('3. Добавить обычного гражданина')
  78.     print('4. Добавить гражданина с плохой историей')
  79.     print('5. Вывести информацию')
  80.     print('0. Выход')
  81.  
  82. def input_data_client():
  83.     print('Name: ')
  84.     name = input()
  85.     print('Age: ')
  86.     age = int(input())
  87.     print('Rating: ')
  88.     rating = int(input())
  89.     print('Discount: ')
  90.     discount = int(input())
  91.     return [ name, age, rating, discount ]
  92.  
  93. command = -1
  94. dep = CreditDepartament(6.5)
  95. while command != 0:
  96.     print_menu()
  97.     print('Введите команду: ')
  98.     command = int(input())
  99.     if command == 1:
  100.         data = input_data_client()
  101.         dep.add_client(Employee(data[0], data[1], data[2], data[3]))
  102.     elif command == 2:
  103.         data = input_data_client()
  104.         dep.add_client(Privileges(data[0], data[1], data[2], data[3]))
  105.     elif command == 3:
  106.         data = input_data_client()
  107.         dep.add_client(OrdinaryCitizen(data[0], data[1], data[2], data[3]))
  108.     elif command == 4:
  109.         data = input_data_client()
  110.         dep.add_client(CitizenBadHistory(data[0], data[1], data[2], data[3]))
  111.     elif command == 5:
  112.         print(dep.credit_decision())
  113.  
Advertisement
Add Comment
Please, Sign In to add comment