From da55f90137302557e39438a5754dbf53bcdca901 Mon Sep 17 00:00:00 2001 From: Lexenburgir Date: Mon, 17 Jun 2024 21:22:47 +0300 Subject: [PATCH 1/4] qas --- tasks/practice1/practice1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/practice1/practice1.py b/tasks/practice1/practice1.py index 030da70..48f8882 100644 --- a/tasks/practice1/practice1.py +++ b/tasks/practice1/practice1.py @@ -10,7 +10,7 @@ def concatenate_strings(a: str, b: str) -> str: # пиши свой код здесь - return result + return a + b def calculate_salary(total_compensation: int) -> float: @@ -24,4 +24,4 @@ def calculate_salary(total_compensation: int) -> float: # пиши свой код здесь - return result + return total_compensation * 0.87 From 197f2209066c309b04564daaaeefe5a306eed734 Mon Sep 17 00:00:00 2001 From: Lexenburgir Date: Mon, 17 Jun 2024 23:03:12 +0300 Subject: [PATCH 2/4] qas --- tasks/practice1/practice1.py | 8 ++++++-- tasks/practice2/practice2.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tasks/practice1/practice1.py b/tasks/practice1/practice1.py index 48f8882..8437c28 100644 --- a/tasks/practice1/practice1.py +++ b/tasks/practice1/practice1.py @@ -10,7 +10,9 @@ def concatenate_strings(a: str, b: str) -> str: # пиши свой код здесь - return a + b + result = a + b + + return result def calculate_salary(total_compensation: int) -> float: @@ -24,4 +26,6 @@ def calculate_salary(total_compensation: int) -> float: # пиши свой код здесь - return total_compensation * 0.87 + result = total_compensation * 0.87 + + return result diff --git a/tasks/practice2/practice2.py b/tasks/practice2/practice2.py index 008f6d1..e8c7678 100644 --- a/tasks/practice2/practice2.py +++ b/tasks/practice2/practice2.py @@ -1,3 +1,4 @@ +import random from typing import Iterable UNCULTURED_WORDS = ('kotleta', 'pirog') @@ -13,6 +14,9 @@ def greet_user(name: str) -> str: """ # пиши код здесь + + greeting = 'Hello' + name + return greeting @@ -29,6 +33,9 @@ def get_amount() -> float: """ # пиши код здесь + + amount = round(random.uniform(100, 1000000), 2) + return amount @@ -43,6 +50,9 @@ def is_phone_correct(phone_number: str) -> bool: """ # пиши код здесь + + result = (len(phone_number) == 12) & (phone_number[:2] == '+7') & phone_number[2:].isnumeric() + return result @@ -59,6 +69,9 @@ def is_amount_correct(current_amount: float, transfer_amount: str) -> bool: """ # пиши код здесь + + result = current_amount >= float(transfer_amount) + return result @@ -78,6 +91,20 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str: """ # пиши код здесь + + result = text.lower() + for i in range(2, len(result)): + result = result.replace(' ' * i, ' ') + if result[0] == ' ': + result = result[1:] + if result[-1] == ' ': + result = result[:-1] + result = result.replace('"', '') + result = result.replace('\'', '') + for i in uncultured_words: + result = result.replace(i, '#' * len(i)) + result = result.upper()[0] + result[1:] + return result @@ -101,4 +128,8 @@ def create_request_for_loan(user_info: str) -> str: """ # пиши код здесь + + x = user_info.split(',') + result = 'Фамилия: ' + x[0] + '\nИмя: ' + x[1] + '\nОтчество: ' + x[2] + '\nДата рождения: ' + x[3] + '\nЗапрошенная сумма: ' + x[4] + return result From d253f8b5700970aa0b238e34dee8b62979ad6d4a Mon Sep 17 00:00:00 2001 From: Lexenburgir Date: Mon, 17 Jun 2024 23:49:11 +0300 Subject: [PATCH 3/4] qwas --- tasks/practice3/practice3.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tasks/practice3/practice3.py b/tasks/practice3/practice3.py index 9115c9c..d6380ba 100644 --- a/tasks/practice3/practice3.py +++ b/tasks/practice3/practice3.py @@ -1,4 +1,6 @@ +import csv from pathlib import Path +import string from typing import Dict, Any, List, Optional @@ -27,8 +29,13 @@ def count_words(text: str) -> Dict[str, int]: """ # пиши свой код здесь + result = {} + words = [word.strip(string.punctuation) for word in text.lower().split() if word.strip(string.punctuation).isalnum()] + for x in words: + if x.isalpha(): + result[x] = result.get(x, 0) + 1 - return {} + return result def exp_list(numbers: List[int], exp: int) -> List[int]: @@ -42,7 +49,7 @@ def exp_list(numbers: List[int], exp: int) -> List[int]: # пиши свой код здесь - return [] + return [x**exp for x in numbers] def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float: @@ -58,6 +65,11 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) :return: размер кешбека """ + result = float(0) + + for x in operations: + result += x['amount'] * (0.05 if x['category'] in special_category else 0.01) + return result @@ -100,5 +112,10 @@ def csv_reader(header: str) -> int: """ # пиши свой код здесь + + a = set() + with get_path_to_file().open('r') as x: + for i in csv.DictReader(x): + a.add(i[header]) - return 0 + return len(a) From aa24a1a8b6f08635f330e341f7798b41dd2281a5 Mon Sep 17 00:00:00 2001 From: Lexenburgir Date: Mon, 17 Jun 2024 23:59:59 +0300 Subject: [PATCH 4/4] qw --- tasks/practice4/practice4.py | 13 +++++++++++++ tasks/practice5/employee.py | 24 ++++++++++++++++++++++++ tasks/practice5/team.py | 19 ++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/tasks/practice4/practice4.py b/tasks/practice4/practice4.py index a7d6b8d..9d15a2f 100644 --- a/tasks/practice4/practice4.py +++ b/tasks/practice4/practice4.py @@ -40,4 +40,17 @@ def search_phone(content: Any, name: str) -> Optional[str]: # пиши свой код здесь + if isinstance(content, list): + for x in content: + if search_phone(x, name): + return search_phone(x, name) + + if isinstance(content, dict): + if content.get('name') == name: + return content.get('phone') + else: + for x in content.values(): + if search_phone(x, name): + return search_phone(x, name) + return None diff --git a/tasks/practice5/employee.py b/tasks/practice5/employee.py index 1d7bad8..cad4b59 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) \ No newline at end of file diff --git a/tasks/practice5/team.py b/tasks/practice5/team.py index 934796c..5e6adc2 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("Only employees can be added to the team") def remove_member(self, member: Employee) -> None: """ @@ -44,6 +51,12 @@ def remove_member(self, member: Employee) -> None: """ # пиши свой код здесь + if not isinstance(member, Employee): + raise TypeError("member is not Employee") + elif member not in self.__members: + raise NoSuchMemberError(self.name, member) + else: + self.__members.remove(member) def get_members(self) -> Set[Employee]: """ @@ -52,6 +65,10 @@ def get_members(self) -> Set[Employee]: """ # пиши свой код здесь + return set(self.__members) + + def __str__(self): + return f"team: {self.name} manager: {self.manager.name} number of members: {len(self.__members)}" def show(self) -> None: """ @@ -64,4 +81,4 @@ def show(self) -> None: Задача: доработать класс таким образом, чтобы метод выполнял свою функцию, не меняя содержимое этого метода """ - print(self) + print(self) \ No newline at end of file