diff --git a/tasks/practice1/practice1.py b/tasks/practice1/practice1.py index 030da70..177897f 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: @@ -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..a1868c6 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 = "Привет, " + name + "!" return greeting @@ -29,7 +31,8 @@ def get_amount() -> float: """ # пиши код здесь - return amount + amount = uniform(100, 1000000) + return round(amount, 2) def is_phone_correct(phone_number: str) -> bool: @@ -43,7 +46,8 @@ def is_phone_correct(phone_number: str) -> bool: """ # пиши код здесь - return result + + return len(phone_number) == 12 and phone_number[:2] == "+7" and phone_number[2:].isnumeric() def is_amount_correct(current_amount: float, transfer_amount: str) -> bool: @@ -59,7 +63,7 @@ def is_amount_correct(current_amount: float, transfer_amount: str) -> bool: """ # пиши код здесь - return result + return current_amount >= float(transfer_amount) def moderate_text(text: str, uncultured_words: Iterable[str]) -> str: @@ -78,6 +82,10 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str: """ # пиши код здесь + result = text.lower().strip().replace("\"", "").replace("\'", "") + for uncultured_word in uncultured_words: + result = result.replace(uncultured_word, "#"*len(uncultured_word)) + result = result.replace(result[0], result[0].upper(), 1) return result @@ -101,4 +109,11 @@ def create_request_for_loan(user_info: str) -> str: """ # пиши код здесь + data = user_info.split(",") + result = (f"Фамилия: {data[0]}\n" + f"Имя: {data[1]}\n" + f"Отчество: {data[2]}\n" + f"Дата рождения: {data[3]}\n" + f"Запрошенная сумма: {data[4]}") + return result diff --git a/tasks/practice3/practice3.py b/tasks/practice3/practice3.py index 9115c9c..582e6ad 100644 --- a/tasks/practice3/practice3.py +++ b/tasks/practice3/practice3.py @@ -1,5 +1,6 @@ from pathlib import Path from typing import Dict, Any, List, Optional +import csv def count_words(text: str) -> Dict[str, int]: @@ -27,8 +28,22 @@ def count_words(text: str) -> Dict[str, int]: """ # пиши свой код здесь + signs = [",", ".", "!", "?"] + result = {} - return {} + filtered_text = text.strip().lower() + for sign in signs: + filtered_text = filtered_text.replace(sign, "") + + for word in filtered_text.split(): + is_word = not any((letter.isdigit() or len(word) <= 1) for letter in word) + if is_word: + if word in result.keys(): + result[word] += 1 + else: + result[word] = 1 + + return result def exp_list(numbers: List[int], exp: int) -> List[int]: @@ -41,8 +56,7 @@ def exp_list(numbers: List[int], exp: int) -> List[int]: """ # пиши свой код здесь - - return [] + return [pow(item, exp) for item in numbers] def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float: @@ -57,7 +71,9 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) :param special_category: список категорий повышенного кешбека :return: размер кешбека """ - + result = 0.0 + for operation in operations: + result += operation["amount"] * (0.05 if operation["category"] in special_category else 0.01) return result @@ -100,5 +116,10 @@ def csv_reader(header: str) -> int: """ # пиши свой код здесь + result = [] + with open(get_path_to_file(), "r") as csv_file: + data = csv.DictReader(csv_file) + for item in data: + result.append(item[header]) - return 0 + return len(set(result)) diff --git a/tasks/practice4/practice4.py b/tasks/practice4/practice4.py index a7d6b8d..29252e3 100644 --- a/tasks/practice4/practice4.py +++ b/tasks/practice4/practice4.py @@ -39,5 +39,15 @@ def search_phone(content: Any, name: str) -> Optional[str]: """ # пиши свой код здесь - + if isinstance(content, list): + for item in content: + if result := search_phone(item, name): + return result + + if isinstance(content, dict): + if content.get("name") == name: + return content.get("phone") + for value in content.values(): + if result := search_phone(value, name): + return result return None diff --git a/tasks/practice5/employee.py b/tasks/practice5/employee.py index 1d7bad8..d2abf55 100644 --- a/tasks/practice5/employee.py +++ b/tasks/practice5/employee.py @@ -39,6 +39,12 @@ 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 +52,7 @@ def get_salary(self) -> int: """ # пиши свой код здесь + return self._salary def __eq__(self, other: object) -> bool: """ @@ -56,6 +63,13 @@ 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 e: + raise ValueError from e def __str__(self): """ @@ -64,6 +78,7 @@ def __str__(self): """ # пиши свой код здесь + return f"name: {self.name} position: {self.position}" def __hash__(self): return id(self) @@ -83,7 +98,8 @@ def __init__(self, name: str, salary: int, language: str): """ # пиши свой код здесь - + self.language = language + super().__init__(name, self.position, salary) class Manager(Employee): """ @@ -98,3 +114,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..8e2aae0 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,13 @@ def remove_member(self, member: Employee) -> None: """ # пиши свой код здесь + if not isinstance(member, Employee): + raise TypeError + + try: + self.__members.remove(member) + except KeyError as e: + raise NoSuchMemberError(self.name, member) from e def get_members(self) -> Set[Employee]: """ @@ -52,6 +65,12 @@ def get_members(self) -> Set[Employee]: """ # пиши свой код здесь + new_set = self.__members.copy() + return new_set + + def __str__(self): + return f"team: {self.name} manager: {self.manager.name} " \ + f"number of members: {len(self.__members)}" def show(self) -> None: """