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
53 changes: 47 additions & 6 deletions tasks/practice2/practice2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def greet_user(name: str) -> str:
"""

# пиши код здесь
greeting = 'Привет' + name
return greeting


Expand All @@ -29,6 +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


Expand All @@ -43,8 +52,17 @@ def is_phone_correct(phone_number: str) -> bool:
"""

# пиши код здесь
return result
if len(phone_number) != 12:
return False

if phone_number[:2] != "+7":
return False


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:
"""
Expand All @@ -59,7 +77,9 @@ def is_amount_correct(current_amount: float, transfer_amount: str) -> bool:
"""

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


def moderate_text(text: str, uncultured_words: Iterable[str]) -> str:
Expand All @@ -78,27 +98,48 @@ 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


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(",")
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



41 changes: 37 additions & 4 deletions tasks/practice3/practice3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from pathlib import Path
import csv
import re
from typing import Dict, Any, List, Optional


Expand Down Expand Up @@ -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]:
Expand All @@ -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:
Expand All @@ -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


Expand Down Expand Up @@ -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)
14 changes: 14 additions & 0 deletions tasks/practice4/practice4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion 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):
"""

# пиши свой код здесь
if not isinstance(salary, int):
raise ValueError('Incorrect data')
self.name = name
self.position = position
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:
raise ValueError

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,7 +96,8 @@ def __init__(self, name: str, salary: int, language: str):
"""

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

self.language = language
super().__init__(name, self.position, salary)

class Manager(Employee):
"""
Expand All @@ -98,3 +112,4 @@ def __init__(self, name: str, salary: int):
"""

# пиши свой код здесь
super().__init__(name, "manager", salary)
17 changes: 17 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
if member not in self.__members:
raise NoSuchMemberError(self.name, member)
else:
self.__members.remove(member)

def get_members(self) -> Set[Employee]:
"""
Expand All @@ -52,6 +64,7 @@ def get_members(self) -> Set[Employee]:
"""

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

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