From 52089b08421822864c099b3687f8a41af3155bb9 Mon Sep 17 00:00:00 2001 From: "konovdaniil926@gmail.com" Date: Mon, 17 Jun 2024 18:12:31 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=88=D1=91=D0=BB!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/practice1/practice1.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tasks/practice1/practice1.py b/tasks/practice1/practice1.py index 030da70..f43e125 100644 --- a/tasks/practice1/practice1.py +++ b/tasks/practice1/practice1.py @@ -9,6 +9,8 @@ def concatenate_strings(a: str, b: str) -> str: """ # пиши свой код здесь + + result = a + b return result @@ -24,4 +26,6 @@ def calculate_salary(total_compensation: int) -> float: # пиши свой код здесь + result = (100 - 13) / 100 * total_compensation + return result From e7ccf74b3cb3c40dd749629ba9b632ecea3e4eb9 Mon Sep 17 00:00:00 2001 From: "konovdaniil926@gmail.com" Date: Mon, 17 Jun 2024 19:53:13 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=91=D0=BB=D0=B8=D0=BD,=20=D1=8F=20=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/practice2/practice2.py | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tasks/practice2/practice2.py b/tasks/practice2/practice2.py index 008f6d1..05fe9da 100644 --- a/tasks/practice2/practice2.py +++ b/tasks/practice2/practice2.py @@ -1,4 +1,5 @@ from typing import Iterable +import random UNCULTURED_WORDS = ('kotleta', 'pirog') @@ -13,6 +14,9 @@ def greet_user(name: str) -> str: """ # пиши код здесь + + greeting = f"Божиею поспешествующею милостию {name}, император и самодержец Всероссийский, Московский, Киевский, Владимирский, Новгородский; царь Казанский, царь Астраханский, царь Польский, царь Сибирский, царь Херсонеса Таврического, царь Грузинский; государь Псковский и великий князь Смоленский, Литовский, Волынский, Подольский и Финляндский; князь Эстляндский, Лифляндский, Курляндский и Семигальский, Самогитский, Белостокский, Корельский, Тверский, Югорский, Пермский, Вятский, Болгарский и иных; государь и великий князь Новагорода низовския земли, Черниговский, Рязанский, Полотский, Ростовский, Ярославский, Белозерский, Удорский, Обдорский, Кондийский, Витебский, Мстиславский и всея северныя страны повелитель; и государь Иверския, Карталинския и Кабардинския земли и области Арменския; Черкасских и Горских князей и иных наследный государь и обладатель, государь Туркестанский; наследник Норвежский, герцог Шлезвиг-Голштейнский, Стормарнский, Дитмарсенский и Ольденбургский и прочая, и прочая, и прочая" + return greeting @@ -29,6 +33,10 @@ def get_amount() -> float: """ # пиши код здесь + + amount = random.randint(100 * 100, 1000000 * 100) + amount /= 100 + return amount @@ -43,6 +51,12 @@ def is_phone_correct(phone_number: str) -> bool: """ # пиши код здесь + + result = True + result &= len(phone_number) == 12 + result &= phone_number[:2] == "+7" + result &= phone_number[1:].isnumeric() + return result @@ -59,6 +73,9 @@ def is_amount_correct(current_amount: float, transfer_amount: str) -> bool: """ # пиши код здесь + + result = current_amount >= float(transfer_amount) + return result @@ -78,6 +95,18 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str: """ # пиши код здесь + + text = text.lower() + uncultured_words = [plohoe_slovo.lower() for plohoe_slovo in uncultured_words] + text = text.translate({ord(character): None for character in '\'"'}) + smeshnaya_narezka = text.split(' ') + smeshnaya_narezka = [slovo for slovo in smeshnaya_narezka if slovo != ''] + result = ' '.join(smeshnaya_narezka) + for plohoe_slovo in uncultured_words: + while plohoe_slovo in result: + result = result.replace(plohoe_slovo, len(plohoe_slovo) * '#') + result = result.capitalize() + return result @@ -101,4 +130,12 @@ def create_request_for_loan(user_info: str) -> str: """ # пиши код здесь + + porezal = user_info.split(",") + result = "Фамилия: " + porezal[0] +\ + "\nИмя: " + porezal[1] +\ + "\nОтчество: " + porezal[2] +\ + "\nДата рождения: " + porezal[3] +\ + "\nЗапрошенная сумма: " + porezal[4] + return result From 8e9c20a86900602f7c8690da30eca1719ed631a2 Mon Sep 17 00:00:00 2001 From: "konovdaniil926@gmail.com" Date: Mon, 17 Jun 2024 23:16:03 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=91=D0=B0=D1=81=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BD=D0=B8=D0=BA=D0=BE=D0=B3=D0=BE=20=D0=BD=D0=B5=20=D1=83?= =?UTF-8?q?=D0=B1=D0=B8=D0=B2=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/practice3/practice3.py | 34 +++++++++++++++++++++++++++++----- tasks/practice4/practice4.py | 18 ++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/tasks/practice3/practice3.py b/tasks/practice3/practice3.py index 9115c9c..ba39eeb 100644 --- a/tasks/practice3/practice3.py +++ b/tasks/practice3/practice3.py @@ -1,6 +1,7 @@ from pathlib import Path from typing import Dict, Any, List, Optional - +import csv +import string def count_words(text: str) -> Dict[str, int]: """ @@ -28,7 +29,22 @@ def count_words(text: str) -> Dict[str, int]: # пиши свой код здесь - return {} + text = text + '!' + + baikal = str() + result = dict() + + for titikaka in text: + if titikaka not in string.punctuation and titikaka != ' ': + baikal = baikal + titikaka + else: + if len(baikal) > 1 and baikal.isalpha(): + if baikal.lower() in result: + result[baikal.lower()] += 1 + else: + result[baikal.lower()] = 1 + baikal = '' + return result def exp_list(numbers: List[int], exp: int) -> List[int]: @@ -41,8 +57,8 @@ def exp_list(numbers: List[int], exp: int) -> List[int]: """ # пиши свой код здесь - - return [] + + return [ pivo ** exp for pivo in numbers ] def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float: @@ -57,6 +73,10 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) :param special_category: список категорий повышенного кешбека :return: размер кешбека """ + result = 0 + for berezka in operations: + mul = 5 if berezka['category'] in special_category else 1 + result += berezka['amount'] * mul / 100 return result @@ -101,4 +121,8 @@ def csv_reader(header: str) -> int: # пиши свой код здесь - return 0 + with get_path_to_file().open('r') as csvfile: + gazmanov = set() + for pugacheva in csv.DictReader(csvfile): + gazmanov.add(pugacheva[header]) + return len(gazmanov) \ No newline at end of file diff --git a/tasks/practice4/practice4.py b/tasks/practice4/practice4.py index a7d6b8d..487c1a2 100644 --- a/tasks/practice4/practice4.py +++ b/tasks/practice4/practice4.py @@ -40,4 +40,22 @@ def search_phone(content: Any, name: str) -> Optional[str]: # пиши свой код здесь + if isinstance(content, str): + return None + + pupa = None + if isinstance(content, dict): + pupa = list() + if content.get('name') == name: + return content['phone'] + for lupa in content: + pupa.append(lupa) + pupa.append(content[lupa]) + else: + pupa = content + if hasattr(pupa, '__iter__'): + for chtoto in pupa: + now = search_phone(chtoto, name) + if now != None: + return now return None From e084e2fd6bb1c621e7e765d47df45983f3558bd6 Mon Sep 17 00:00:00 2001 From: "konovdaniil926@gmail.com" Date: Mon, 17 Jun 2024 23:46:10 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=A0=D0=B5=D0=B9=D0=BA=D1=8C=D1=8F=D0=B2?= =?UTF-8?q?=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/practice5/employee.py | 24 ++++++++++++++++++++++++ tasks/practice5/team.py | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tasks/practice5/employee.py b/tasks/practice5/employee.py index 1d7bad8..761690e 100644 --- a/tasks/practice5/employee.py +++ b/tasks/practice5/employee.py @@ -40,6 +40,13 @@ def __init__(self, name: str, position: str, salary: int): # пиши свой код здесь + if not isinstance(name, str) or not isinstance(position, str) or not isinstance(salary, int): + raise ValueError + + self.name = name + self.position = position + self._salary = salary + def get_salary(self) -> int: """ Метод возвращает зарплату сотрудника. @@ -47,6 +54,8 @@ def get_salary(self) -> int: # пиши свой код здесь + return self._salary + def __eq__(self, other: object) -> bool: """ Задача: реализовать метод сравнение двух сотрудников, чтобы все тесты проходили. @@ -57,6 +66,15 @@ def __eq__(self, other: object) -> bool: # пиши свой код здесь + if not isinstance(other, Employee): + raise TypeError + + try: + return get_position_level(self.position) == get_position_level(other.position) + except NoSuchPositionError: + raise ValueError + + def __str__(self): """ Задача: реализовать строковое представление объекта. @@ -65,6 +83,8 @@ def __str__(self): # пиши свой код здесь + return f'name: {self.name} position: {self.position}' + def __hash__(self): return id(self) @@ -84,6 +104,9 @@ def __init__(self, name: str, salary: int, language: str): # пиши свой код здесь + super().__init__(name, self.position, salary) + self.language = language + class Manager(Employee): """ @@ -98,3 +121,4 @@ def __init__(self, name: str, salary: int): """ # пиши свой код здесь + super().__init__(name, self.position, salary) diff --git a/tasks/practice5/team.py b/tasks/practice5/team.py index 934796c..4326c36 100644 --- a/tasks/practice5/team.py +++ b/tasks/practice5/team.py @@ -28,6 +28,9 @@ def __init__(self, name: str, manager: Manager): """ # пиши свой код здесь + self.name = name + self.manager = manager + self.__members = set() def add_member(self, member: Employee) -> None: """ @@ -36,6 +39,10 @@ def add_member(self, member: Employee) -> None: """ # пиши свой код здесь + if isinstance(member, Employee): + self.__members.add(member) + else: + raise TypeError def remove_member(self, member: Employee) -> None: """ @@ -45,6 +52,14 @@ def remove_member(self, member: Employee) -> None: # пиши свой код здесь + if not isinstance(member, Employee): + raise TypeError + + if member in self.__members: + self.__members.remove(member) + else: + raise NoSuchMemberError(self.name, member) + def get_members(self) -> Set[Employee]: """ Задача: реализовать метод возвращения списка участков команды та, @@ -52,6 +67,8 @@ def get_members(self) -> Set[Employee]: """ # пиши свой код здесь + + return set(self.__members) def show(self) -> None: """ @@ -65,3 +82,6 @@ def show(self) -> None: этого метода """ print(self) + + def __str__(self): + return f'team: {self.name} manager: {self.manager.name} number of members: {len(self.__members)}' \ No newline at end of file