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 @@ -9,6 +9,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 = (100 - 13) / 100 * total_compensation

return result
37 changes: 37 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
import random

UNCULTURED_WORDS = ('kotleta', 'pirog')

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

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

greeting = f"Божиею поспешествующею милостию {name}, император и самодержец Всероссийский, Московский, Киевский, Владимирский, Новгородский; царь Казанский, царь Астраханский, царь Польский, царь Сибирский, царь Херсонеса Таврического, царь Грузинский; государь Псковский и великий князь Смоленский, Литовский, Волынский, Подольский и Финляндский; князь Эстляндский, Лифляндский, Курляндский и Семигальский, Самогитский, Белостокский, Корельский, Тверский, Югорский, Пермский, Вятский, Болгарский и иных; государь и великий князь Новагорода низовския земли, Черниговский, Рязанский, Полотский, Ростовский, Ярославский, Белозерский, Удорский, Обдорский, Кондийский, Витебский, Мстиславский и всея северныя страны повелитель; и государь Иверския, Карталинския и Кабардинския земли и области Арменския; Черкасских и Горских князей и иных наследный государь и обладатель, государь Туркестанский; наследник Норвежский, герцог Шлезвиг-Голштейнский, Стормарнский, Дитмарсенский и Ольденбургский и прочая, и прочая, и прочая"

return greeting


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

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

amount = random.randint(100 * 100, 1000000 * 100)
amount /= 100

return amount


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

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

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

return result


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

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

result = current_amount >= float(transfer_amount)

return result


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

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

text = text.lower()
uncultured_words = [plohoe_slovo.lower() for plohoe_slovo in uncultured_words]
text = text.translate({ord(character): None for character in '\'"'})
smeshnaya_narezka = text.split(' ')
smeshnaya_narezka = [slovo for slovo in smeshnaya_narezka if slovo != '']
result = ' '.join(smeshnaya_narezka)
for plohoe_slovo in uncultured_words:
while plohoe_slovo in result:
result = result.replace(plohoe_slovo, len(plohoe_slovo) * '#')
result = result.capitalize()

return result


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

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

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

return result
34 changes: 29 additions & 5 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 csv
import string

def count_words(text: str) -> Dict[str, int]:
"""
Expand Down Expand Up @@ -28,7 +29,22 @@ def count_words(text: str) -> Dict[str, int]:

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

return {}
text = text + '!'

baikal = str()
result = dict()

for titikaka in text:
if titikaka not in string.punctuation and titikaka != ' ':
baikal = baikal + titikaka
else:
if len(baikal) > 1 and baikal.isalpha():
if baikal.lower() in result:
result[baikal.lower()] += 1
else:
result[baikal.lower()] = 1
baikal = ''
return result


def exp_list(numbers: List[int], exp: int) -> List[int]:
Expand All @@ -41,8 +57,8 @@ def exp_list(numbers: List[int], exp: int) -> List[int]:
"""

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

return []
return [ pivo ** exp for pivo in numbers ]


def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float:
Expand All @@ -57,6 +73,10 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str])
:param special_category: список категорий повышенного кешбека
:return: размер кешбека
"""
result = 0
for berezka in operations:
mul = 5 if berezka['category'] in special_category else 1
result += berezka['amount'] * mul / 100

return result

Expand Down Expand Up @@ -101,4 +121,8 @@ def csv_reader(header: str) -> int:

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

return 0
with get_path_to_file().open('r') as csvfile:
gazmanov = set()
for pugacheva in csv.DictReader(csvfile):
gazmanov.add(pugacheva[header])
return len(gazmanov)
18 changes: 18 additions & 0 deletions tasks/practice4/practice4.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,22 @@ def search_phone(content: Any, name: str) -> Optional[str]:

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

if isinstance(content, str):
return None

pupa = None
if isinstance(content, dict):
pupa = list()
if content.get('name') == name:
return content['phone']
for lupa in content:
pupa.append(lupa)
pupa.append(content[lupa])
else:
pupa = content
if hasattr(pupa, '__iter__'):
for chtoto in pupa:
now = search_phone(chtoto, name)
if now != None:
return now
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)
20 changes: 20 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,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:
"""
Expand All @@ -45,13 +52,23 @@ def remove_member(self, member: Employee) -> None:

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

if not isinstance(member, Employee):
raise TypeError

if member in self.__members:
self.__members.remove(member)
else:
raise NoSuchMemberError(self.name, member)

def get_members(self) -> Set[Employee]:
"""
Задача: реализовать метод возвращения списка участков команды та,
чтобы из вне нельзя было поменять список участников внутри класса
"""

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

return set(self.__members)

def show(self) -> None:
"""
Expand All @@ -65,3 +82,6 @@ def show(self) -> None:
этого метода
"""
print(self)

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