Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tasks/practice1/practice1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def concatenate_strings(a: str, b: str) -> str:
"""

# пиши свой код здесь

result = a + b
return result


Expand All @@ -23,5 +23,5 @@ def calculate_salary(total_compensation: int) -> float:
"""

# пиши свой код здесь

result = total_compensation * 0.87
return result
18 changes: 18 additions & 0 deletions tasks/practice2/practice2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Iterable
from random import uniform

UNCULTURED_WORDS = ('kotleta', 'pirog')

Expand All @@ -13,6 +14,7 @@ def greet_user(name: str) -> str:
"""

# пиши код здесь
greeting = f"Hello, {name}!"
return greeting


Expand All @@ -29,6 +31,7 @@ def get_amount() -> float:
"""

# пиши код здесь
amount = round(uniform(100, 1000000), 2)
return amount


Expand All @@ -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


Expand All @@ -59,6 +65,7 @@ def is_amount_correct(current_amount: float, transfer_amount: str) -> bool:
"""

# пиши код здесь
result = current_amount >= float(transfer_amount)
return result


Expand All @@ -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


Expand All @@ -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
24 changes: 17 additions & 7 deletions tasks/practice3/practice3.py
Original file line number Diff line number Diff line change
@@ -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]:
"""
Expand All @@ -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]:
Expand All @@ -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:
Expand All @@ -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


Expand Down Expand Up @@ -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)
18 changes: 17 additions & 1 deletion tasks/practice4/practice4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions tasks/practice5/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ 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:
"""
Метод возвращает зарплату сотрудника.
"""

# пиши свой код здесь
return self._salary

def __eq__(self, other: object) -> bool:
"""
Expand All @@ -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):
"""
Expand All @@ -64,6 +76,7 @@ def __str__(self):
"""

# пиши свой код здесь
return f'name: {self.name} position: {self.position}'

def __hash__(self):
return id(self)
Expand All @@ -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):
Expand All @@ -98,3 +114,5 @@ def __init__(self, name: str, salary: int):
"""

# пиши свой код здесь
self.name = name
self._salary = salary
16 changes: 16 additions & 0 deletions tasks/practice5/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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:
"""
Expand All @@ -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]:
"""
Expand All @@ -52,6 +64,7 @@ def get_members(self) -> Set[Employee]:
"""

# пиши свой код здесь
return set(self.__members)

def show(self) -> None:
"""
Expand All @@ -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)}'