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: 4 additions & 0 deletions tasks/practice1/practice1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def concatenate_strings(a: str, b: str) -> str:

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

result = a + b

return result


Expand All @@ -24,4 +26,6 @@ def calculate_salary(total_compensation: int) -> float:

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

result = total_compensation * 0.87

return result
31 changes: 31 additions & 0 deletions tasks/practice2/practice2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from typing import Iterable

UNCULTURED_WORDS = ('kotleta', 'pirog')
Expand All @@ -13,6 +14,9 @@ def greet_user(name: str) -> str:
"""

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

greeting = 'Hello' + name

return greeting


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

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

amount = round(random.uniform(100, 1000000), 2)

return amount


Expand All @@ -43,6 +50,9 @@ def is_phone_correct(phone_number: str) -> bool:
"""

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

result = (len(phone_number) == 12) & (phone_number[:2] == '+7') & phone_number[2:].isnumeric()

return result


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

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

result = current_amount >= float(transfer_amount)

return result


Expand All @@ -78,6 +91,20 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str:
"""

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

result = text.lower()
for i in range(2, len(result)):
result = result.replace(' ' * i, ' ')
if result[0] == ' ':
result = result[1:]
if result[-1] == ' ':
result = result[:-1]
result = result.replace('"', '')
result = result.replace('\'', '')
for i in uncultured_words:
result = result.replace(i, '#' * len(i))
result = result.upper()[0] + result[1:]

return result


Expand All @@ -101,4 +128,8 @@ def create_request_for_loan(user_info: str) -> str:
"""

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

x = user_info.split(',')
result = 'Фамилия: ' + x[0] + '\nИмя: ' + x[1] + '\nОтчество: ' + x[2] + '\nДата рождения: ' + x[3] + '\nЗапрошенная сумма: ' + x[4]

return result
23 changes: 20 additions & 3 deletions tasks/practice3/practice3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import csv
from pathlib import Path
import string
from typing import Dict, Any, List, Optional


Expand Down Expand Up @@ -27,8 +29,13 @@ def count_words(text: str) -> Dict[str, int]:
"""

# пиши свой код здесь
result = {}
words = [word.strip(string.punctuation) for word in text.lower().split() if word.strip(string.punctuation).isalnum()]
for x in words:
if x.isalpha():
result[x] = result.get(x, 0) + 1

return {}
return result


def exp_list(numbers: List[int], exp: int) -> List[int]:
Expand All @@ -42,7 +49,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 @@ -58,6 +65,11 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str])
:return: размер кешбека
"""

result = float(0)

for x in operations:
result += x['amount'] * (0.05 if x['category'] in special_category else 0.01)

return result


Expand Down Expand Up @@ -100,5 +112,10 @@ def csv_reader(header: str) -> int:
"""

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

a = set()
with get_path_to_file().open('r') as x:
for i in csv.DictReader(x):
a.add(i[header])

return 0
return len(a)
13 changes: 13 additions & 0 deletions tasks/practice4/practice4.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,17 @@ def search_phone(content: Any, name: str) -> Optional[str]:

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

if isinstance(content, list):
for x in content:
if search_phone(x, name):
return search_phone(x, name)

if isinstance(content, dict):
if content.get('name') == name:
return content.get('phone')
else:
for x in content.values():
if search_phone(x, name):
return search_phone(x, name)

return None
24 changes: 24 additions & 0 deletions tasks/practice5/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,22 @@ def __init__(self, name: str, position: str, salary: int):

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

if not isinstance(name, str) or not isinstance(position, str) or not isinstance(salary, int):
raise ValueError

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 @@ -57,6 +66,15 @@ 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):
"""
Задача: реализовать строковое представление объекта.
Expand All @@ -65,6 +83,8 @@ def __str__(self):

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

return f'name: {self.name} position: {self.position}'

def __hash__(self):
return id(self)

Expand All @@ -84,6 +104,9 @@ def __init__(self, name: str, salary: int, language: str):

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

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


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

# пиши свой код здесь
super().__init__(name, self.position, salary)
19 changes: 18 additions & 1 deletion 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,10 @@ def add_member(self, member: Employee) -> None:
"""

# пиши свой код здесь
if isinstance(member, Employee):
self.__members.add(member)
else:
raise TypeError("Only employees can be added to the team")

def remove_member(self, member: Employee) -> None:
"""
Expand All @@ -44,6 +51,12 @@ def remove_member(self, member: Employee) -> None:
"""

# пиши свой код здесь
if not isinstance(member, Employee):
raise TypeError("member is not Employee")
elif 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 +65,10 @@ def get_members(self) -> Set[Employee]:
"""

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

def __str__(self):
return f"team: {self.name} manager: {self.manager.name} number of members: {len(self.__members)}"

def show(self) -> None:
"""
Expand All @@ -64,4 +81,4 @@ def show(self) -> None:
Задача: доработать класс таким образом, чтобы метод выполнял свою функцию, не меняя содержимое
этого метода
"""
print(self)
print(self)