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..41e718a 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,7 @@ def greet_user(name: str) -> str: """ # пиши код здесь + greeting = 'Привет, ' + name + '!' return greeting @@ -29,6 +31,8 @@ def get_amount() -> float: """ # пиши код здесь + current_number = random.uniform(100, 999999) + amount = float(f"{current_number:.2f}") return amount @@ -43,6 +47,13 @@ def is_phone_correct(phone_number: str) -> bool: """ # пиши код здесь + result = False + if phone_number[0] == "+" and len(phone_number) == 12 and phone_number[1] == "7": + result = True + for i in phone_number[1:]: + if not i.isdigit(): + result = False + break return result @@ -59,6 +70,10 @@ def is_amount_correct(current_amount: float, transfer_amount: str) -> bool: """ # пиши код здесь + if current_amount >= float(transfer_amount): + result = True + else: + result = False return result @@ -78,7 +93,13 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str: """ # пиши код здесь - return result + text = text.replace('\'', '').replace('\"', '') + for word in uncultured_words: + if word in text: + text = text.replace(word, '#' * len(word)) + text = ' '.join(text.split()) + text = text[0].upper() + text[1:].lower() + return text def create_request_for_loan(user_info: str) -> str: @@ -101,4 +122,8 @@ def create_request_for_loan(user_info: str) -> str: """ # пиши код здесь + Info = user_info.split(',') + result = 'Фамилия: ' + Info[0] + '\nИмя: ' + Info[1] + '\nОтчество: ' + Info[2] \ + + '\nДата рождения: ' + Info[3] + '\nЗапрошенная сумма: ' + Info[4] + print(result) return result diff --git a/tasks/practice3/practice3.py b/tasks/practice3/practice3.py index 9115c9c..965058d 100644 --- a/tasks/practice3/practice3.py +++ b/tasks/practice3/practice3.py @@ -1,6 +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 +27,16 @@ def count_words(text: str) -> Dict[str, int]: """ # пиши свой код здесь - - return {} + answer = {} + text = text.lower().replace('!', '').replace('?', '').replace(',', '').replace('.', '').replace(';', '') + text = text.split() + for word in text: + if all(97 <= ord(letter) <= 122 for letter in word): + if word in answer: + answer[word] += 1 + else: + answer[word] = 1 + return answer def exp_list(numbers: List[int], exp: int) -> List[int]: @@ -41,8 +49,8 @@ def exp_list(numbers: List[int], exp: int) -> List[int]: """ # пиши свой код здесь - - return [] + result = [num ** exp for num in numbers] + return result def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float: @@ -57,7 +65,12 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) :param special_category: список категорий повышенного кешбека :return: размер кешбека """ - + result = 0.0 + for operation in operations: + if operation['category'] in special_category: + result += operation['amount'] * 0.05 + else: + result += operation['amount'] * 0.01 return result @@ -100,5 +113,12 @@ def csv_reader(header: str) -> int: """ # пиши свой код здесь + result = set() + + path_to_file = get_path_to_file() + file = open(path_to_file, 'r') + csvFile = csv.DictReader(file) - return 0 + for row in csvFile: + result.add(row[header]) + return len(result) diff --git a/tasks/practice4/practice4.py b/tasks/practice4/practice4.py index a7d6b8d..e3b3e66 100644 --- a/tasks/practice4/practice4.py +++ b/tasks/practice4/practice4.py @@ -39,5 +39,16 @@ def search_phone(content: Any, name: str) -> Optional[str]: """ # пиши свой код здесь - + if isinstance(content, dict): + if 'name' in content and content['name'] == name: + return content.get('phone', None) + for value in content.values(): + phone = search_phone(value, name) + if phone is not None: + return phone + elif isinstance(content, list): + for item in content: + phone = search_phone(item, name) + if phone is not None: + return phone return None diff --git a/tasks/practice5/employee.py b/tasks/practice5/employee.py index 1d7bad8..13e730d 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(position, str) or not isinstance(name, str) or not isinstance(salary, int): + raise ValueError + 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 NoSuchPositionError: + 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, self.position, salary) \ No newline at end of file diff --git a/tasks/practice5/team.py b/tasks/practice5/team.py index 934796c..a3e4039 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: """ @@ -44,6 +51,11 @@ 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) + 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,6 @@ def show(self) -> None: этого метода """ print(self) + + def __str__(self): + return f"team: {self.name} manager: {self.manager.name} number of members: {len(self.get_members())}" \ No newline at end of file