From 09333e040fc6518b21d9a87edf5eceb388aded30 Mon Sep 17 00:00:00 2001 From: VVroli Date: Wed, 17 Apr 2024 19:57:55 +0300 Subject: [PATCH 1/5] pass_practice1 --- 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..21e154a 100644 --- a/tasks/practice1/practice1.py +++ b/tasks/practice1/practice1.py @@ -9,7 +9,7 @@ def concatenate_strings(a: str, b: str) -> str: """ # пиши свой код здесь - + result = a + b return result @@ -23,5 +23,5 @@ def calculate_salary(total_compensation: int) -> float: """ # пиши свой код здесь - + result = total_compensation * 0.87 return result From 310fcf7d6be3f29230005493b81bcb16bf48bed5 Mon Sep 17 00:00:00 2001 From: VVroli Date: Sun, 16 Jun 2024 20:49:18 +0300 Subject: [PATCH 2/5] pass_practice1 --- tasks/practice2/practice2.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tasks/practice2/practice2.py b/tasks/practice2/practice2.py index 008f6d1..3d38b4f 100644 --- a/tasks/practice2/practice2.py +++ b/tasks/practice2/practice2.py @@ -13,6 +13,7 @@ def greet_user(name: str) -> str: """ # пиши код здесь + greeting = 'Привет' + name return greeting @@ -29,6 +30,7 @@ def get_amount() -> float: """ # пиши код здесь + return amount @@ -43,6 +45,15 @@ def is_phone_correct(phone_number: str) -> bool: """ # пиши код здесь + if phone_number[0] == '+': + return True + + if phone_number[1] == '7': + return True + + for x in phone_number[1:]: + if 0 <= x <= 9: + return True return result @@ -59,6 +70,8 @@ def is_amount_correct(current_amount: float, transfer_amount: str) -> bool: """ # пиши код здесь + if int(current_amount) >= int(transfer_amount): + return True return result @@ -85,20 +98,25 @@ def create_request_for_loan(user_info: str) -> str: """ Генерирует заявку на кредит на основе входящей строки. Формат входящий строки: - + Иванов,Петр,Сергеевич,01.01.1991,10000 - + Что должны вернуть на ее основе: - + Фамилия: Иванов Имя: Петр Отчество: Сергеевич Дата рождения: 01.01.1991 Запрошенная сумма: 10000 - + :param user_info: строка с информацией о клиенте :return: текст кредитной заявки """ # пиши код здесь + user_info = user_info.split(',') + result = ('Фамилия: ' + user_info[0] + "/n" + 'Имя: ' + 'user_info[1]/n' + 'Отчество: ' + 'user_info[2]/n' + 'Дата рождения: ' + 'user_info[3]/n' + 'Запрошенная сумма: ' + 'user_info[4]') return result + + + From 68e30a46e62325c2a571af7fd63c781a8fb3d14e Mon Sep 17 00:00:00 2001 From: VVroli Date: Sun, 16 Jun 2024 21:50:19 +0300 Subject: [PATCH 3/5] pass_practice2-3 --- tasks/practice2/practice2.py | 47 +++++++++++++++++++++++++++--------- tasks/practice3/practice3.py | 41 ++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/tasks/practice2/practice2.py b/tasks/practice2/practice2.py index 3d38b4f..ecff744 100644 --- a/tasks/practice2/practice2.py +++ b/tasks/practice2/practice2.py @@ -30,7 +30,14 @@ def get_amount() -> float: """ # пиши код здесь + import random + while True: + amount = random.uniform(100, 1000000) + amount = round(amount, 2) + + if len(str(amount).split(".")[1]) <= 2: + break return amount @@ -45,17 +52,17 @@ def is_phone_correct(phone_number: str) -> bool: """ # пиши код здесь - if phone_number[0] == '+': - return True + if len(phone_number) != 12: + return False - if phone_number[1] == '7': - return True + if phone_number[:2] != "+7": + return False - for x in phone_number[1:]: - if 0 <= x <= 9: - return True - return result + for sym in phone_number[2:]: + if not sym.isdigit(): + return False + return True def is_amount_correct(current_amount: float, transfer_amount: str) -> bool: """ @@ -70,9 +77,9 @@ def is_amount_correct(current_amount: float, transfer_amount: str) -> bool: """ # пиши код здесь - if int(current_amount) >= int(transfer_amount): + if int(current_amount) >= float(transfer_amount): return True - return result + return False def moderate_text(text: str, uncultured_words: Iterable[str]) -> str: @@ -91,6 +98,15 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str: """ # пиши код здесь + text = text.lower().strip() + + text = text.replace('"', '').replace("'", '') + + for word in uncultured_words: + text = text.replace(word, "#" * len(word)) + + result = text[0].upper() + text[1:] + return result @@ -114,8 +130,15 @@ def create_request_for_loan(user_info: str) -> str: """ # пиши код здесь - user_info = user_info.split(',') - result = ('Фамилия: ' + user_info[0] + "/n" + 'Имя: ' + 'user_info[1]/n' + 'Отчество: ' + 'user_info[2]/n' + 'Дата рождения: ' + 'user_info[3]/n' + 'Запрошенная сумма: ' + 'user_info[4]') + user_info = user_info.split(",") + last_name, first_name, middle_name, date_of_birth, requested_amount = user_info + result = ( + f"Фамилия: {last_name}\n" + f"Имя: {first_name}\n" + f"Отчество: {middle_name}\n" + f"Дата рождения: {date_of_birth}\n" + f"Запрошенная сумма: {requested_amount}" + ) return result diff --git a/tasks/practice3/practice3.py b/tasks/practice3/practice3.py index 9115c9c..e5b2a8a 100644 --- a/tasks/practice3/practice3.py +++ b/tasks/practice3/practice3.py @@ -1,4 +1,6 @@ from pathlib import Path +import csv +import re from typing import Dict, Any, List, Optional @@ -27,8 +29,18 @@ def count_words(text: str) -> Dict[str, int]: """ # пиши свой код здесь + text = text.lower() + + word_pattern = re.compile(r"\b[a-z]{2,}\b") + + word_counts = {} + for match in word_pattern.finditer(text): + word = match.group() + word_counts.setdefault(word, 0) + word_counts[word] += 1 + + return word_counts - return {} def exp_list(numbers: List[int], exp: int) -> List[int]: @@ -41,8 +53,12 @@ def exp_list(numbers: List[int], exp: int) -> List[int]: """ # пиши свой код здесь + result = [] - return [] + for number in numbers: + result.append(number ** exp) + + return result def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float: @@ -58,6 +74,17 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) :return: размер кешбека """ + result = 0.0 + + for operation in operations: + amount = operation['amount'] + category = operation['category'] + + if category in special_category: + result += amount * 0.05 + else: + result += amount * 0.01 + return result @@ -100,5 +127,11 @@ def csv_reader(header: str) -> int: """ # пиши свой код здесь - - return 0 + file_path = get_path_to_file() + result = set() + with open(file_path) as file: + reader = csv.DictReader(file) + for row in reader: + result.add(row[header]) + + return len(result) From 941b850e921935c36b8172f1a80b756278348f0b Mon Sep 17 00:00:00 2001 From: VVroli Date: Sun, 16 Jun 2024 22:10:52 +0300 Subject: [PATCH 4/5] pass_practice4 --- tasks/practice4/practice4.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tasks/practice4/practice4.py b/tasks/practice4/practice4.py index a7d6b8d..57ab680 100644 --- a/tasks/practice4/practice4.py +++ b/tasks/practice4/practice4.py @@ -39,5 +39,19 @@ def search_phone(content: Any, name: str) -> Optional[str]: """ # пиши свой код здесь + if isinstance(content, list): + for item in content: + result = search_phone(item, name) + if result is not None: + return result + + + elif isinstance(content, dict): + if content.get('name') == name: + return content.get('phone') + for key in content: + result = search_phone(content[key], name) + if result is not None: + return result return None From 5c8639cdd561dbdaa62b34f7e235b09ab285682f Mon Sep 17 00:00:00 2001 From: VVroli Date: Sun, 16 Jun 2024 23:09:30 +0300 Subject: [PATCH 5/5] pass_practice5 --- tasks/practice5/employee.py | 17 ++++++++++++++++- tasks/practice5/team.py | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tasks/practice5/employee.py b/tasks/practice5/employee.py index 1d7bad8..7c02cfe 100644 --- a/tasks/practice5/employee.py +++ b/tasks/practice5/employee.py @@ -39,6 +39,11 @@ def __init__(self, name: str, position: str, salary: int): """ # пиши свой код здесь + if not isinstance(salary, int): + raise ValueError('Incorrect data') + self.name = name + self.position = position + self._salary = salary def get_salary(self) -> int: """ @@ -46,6 +51,7 @@ def get_salary(self) -> int: """ # пиши свой код здесь + return self._salary def __eq__(self, other: object) -> bool: """ @@ -56,6 +62,12 @@ 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: + raise ValueError def __str__(self): """ @@ -64,6 +76,7 @@ def __str__(self): """ # пиши свой код здесь + return f"name: {self.name} position: {self.position}" def __hash__(self): return id(self) @@ -83,7 +96,8 @@ def __init__(self, name: str, salary: int, language: str): """ # пиши свой код здесь - + self.language = language + super().__init__(name, self.position, salary) class Manager(Employee): """ @@ -98,3 +112,4 @@ def __init__(self, name: str, salary: int): """ # пиши свой код здесь + super().__init__(name, "manager", salary) \ No newline at end of file diff --git a/tasks/practice5/team.py b/tasks/practice5/team.py index 934796c..eacfad6 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,9 @@ def add_member(self, member: Employee) -> None: """ # пиши свой код здесь + if not isinstance(member, Employee): + raise TypeError + self.__members.add(member) def remove_member(self, member: Employee) -> None: """ @@ -44,6 +50,12 @@ def remove_member(self, member: Employee) -> None: """ # пиши свой код здесь + if not isinstance(member, Employee): + raise TypeError + if member not in self.__members: + raise NoSuchMemberError(self.name, member) + else: + self.__members.remove(member) def get_members(self) -> Set[Employee]: """ @@ -52,6 +64,7 @@ def get_members(self) -> Set[Employee]: """ # пиши свой код здесь + return self.__members.copy() def show(self) -> None: """ @@ -65,3 +78,7 @@ def show(self) -> None: этого метода """ print(self) + + def __str__(self): + text = f'team: {self.name} manager: {self.manager.name} number of members: {len(self.__members)}' + return text