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 diff --git a/tasks/practice2/practice2.py b/tasks/practice2/practice2.py index 008f6d1..e31f1d4 100644 --- a/tasks/practice2/practice2.py +++ b/tasks/practice2/practice2.py @@ -1,4 +1,5 @@ from typing import Iterable +from random import uniform UNCULTURED_WORDS = ('kotleta', 'pirog') @@ -13,6 +14,7 @@ def greet_user(name: str) -> str: """ # пиши код здесь + greeting = f"Hello, {name}!" return greeting @@ -29,6 +31,7 @@ def get_amount() -> float: """ # пиши код здесь + amount = round(uniform(100, 1000000), 2) return amount @@ -43,6 +46,9 @@ def is_phone_correct(phone_number: str) -> bool: """ # пиши код здесь + result = len(phone_number) == len("+7xxxxxxxxxx") and \ + phone_number[:2] == "+7" and \ + all(x in list(map(str, list(range(10)))) for x in phone_number[2:]) return result @@ -59,6 +65,7 @@ def is_amount_correct(current_amount: float, transfer_amount: str) -> bool: """ # пиши код здесь + result = current_amount >= float(transfer_amount) return result @@ -78,6 +85,11 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str: """ # пиши код здесь + result = text.strip() + result = result[0].upper() + result[1:].lower() + result = result.replace("\"", "").replace("\'", "") + for bad_word in uncultured_words: + result = result.replace(bad_word, "#" * len(bad_word)) return result @@ -101,4 +113,10 @@ def create_request_for_loan(user_info: str) -> str: """ # пиши код здесь + user_info_list = user_info.split(",") + result = f"Фамилия: {user_info_list[0]}\n" + \ + f"Имя: {user_info_list[1]}\n" + \ + f"Отчество: {user_info_list[2]}\n" + \ + f"Дата рождения: {user_info_list[3]}\n" + \ + f"Запрошенная сумма: {user_info_list[4]}" return result diff --git a/tasks/practice3/practice3.py b/tasks/practice3/practice3.py index 9115c9c..1139afe 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 re +import csv def count_words(text: str) -> Dict[str, int]: """ @@ -27,8 +28,8 @@ def count_words(text: str) -> Dict[str, int]: """ # пиши свой код здесь - - return {} + words = [x.lower() for x in re.split(";|,| |\.|\n|-|!", text) if len(x) > 0 and not any(i for i in range(10) if str(i) in x)] + return {x: words.count(x) for x in words} def exp_list(numbers: List[int], exp: int) -> List[int]: @@ -42,7 +43,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: @@ -57,7 +58,12 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) :param special_category: список категорий повышенного кешбека :return: размер кешбека """ - + result = 0 + for op in operations: + if op.get("category") in special_category: + result += op.get("amount") * 0.05 + else: + result += op.get("amount") * 0.01 return result @@ -100,5 +106,9 @@ def csv_reader(header: str) -> int: """ # пиши свой код здесь - - return 0 + freqs = set() + with open(get_path_to_file()) as file: + reader = csv.DictReader(file) + for row in reader: + freqs.add(row[header]) + return len(freqs) diff --git a/tasks/practice4/practice4.py b/tasks/practice4/practice4.py index a7d6b8d..a3e0040 100644 --- a/tasks/practice4/practice4.py +++ b/tasks/practice4/practice4.py @@ -39,5 +39,21 @@ def search_phone(content: Any, name: str) -> Optional[str]: """ # пиши свой код здесь - + if isinstance(content, list): + for cont in content: + ans = search_phone(cont, name) + if ans is not None: + return ans + return None + + if not isinstance(content, dict): + return None + + if 'name' in content and content['name'] == name: + return content['phone'] + + for key, val in content.items(): + ans = search_phone(val, name) + if ans is not None: + return ans return None diff --git a/tasks/practice5/employee.py b/tasks/practice5/employee.py index 1d7bad8..051ba79 100644 --- a/tasks/practice5/employee.py +++ b/tasks/practice5/employee.py @@ -39,6 +39,11 @@ def __init__(self, name: str, position: str, salary: int): """ # пиши свой код здесь + self.name = name + self.position = position + if not isinstance(salary, int): + raise ValueError + 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 NoSuchPositionError as exp: + raise ValueError from exp 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,6 +96,9 @@ def __init__(self, name: str, salary: int, language: str): """ # пиши свой код здесь + self.name = name + self._salary = salary + self.language = language class Manager(Employee): @@ -98,3 +114,5 @@ def __init__(self, name: str, salary: int): """ # пиши свой код здесь + self.name = name + self._salary = salary diff --git a/tasks/practice5/team.py b/tasks/practice5/team.py index 934796c..2a3d94b 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 + try: + self.__members.remove(member) + except KeyError as exp: + raise NoSuchMemberError(self.name, member) from exp def get_members(self) -> Set[Employee]: """ @@ -52,6 +64,7 @@ def get_members(self) -> Set[Employee]: """ # пиши свой код здесь + return set(self.__members) def show(self) -> None: """ @@ -65,3 +78,6 @@ def show(self) -> None: этого метода """ print(self) + + def __str__(self) -> str: + return f'team: {self.name} manager: {self.manager.name} number of members: {len(self.__members)}' \ No newline at end of file