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 @@ -8,7 +8,7 @@ def concatenate_strings(a: str, b: str) -> str:
:return: результат сложения
"""

# пиши свой код здесь
result = a + b

return result

Expand All @@ -22,6 +22,6 @@ def calculate_salary(total_compensation: int) -> float:
:return: сумма заплаты после вычета налога
"""

# пиши свой код здесь
result = total_compensation * 0.87

return result
25 changes: 24 additions & 1 deletion tasks/practice2/practice2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
from typing import Iterable
import random

UNCULTURED_WORDS = ('kotleta', 'pirog')

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

# пиши код здесь
greeting = "Здарова, " + name
return greeting


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

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


Expand All @@ -43,7 +47,11 @@ def is_phone_correct(phone_number: str) -> bool:
"""

# пиши код здесь
return result
result = re.match('\+7\d{10}', phone_number)
if result is None:
return False
else:
return True


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

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


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

# пиши код здесь
result = text.replace('\'', '').replace('\"', '')
result = ' '.join(result.split())
result = result.capitalize()
for word in uncultured_words:
result = result.replace(word, '#' * len(word))
return result


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

# пиши код здесь
data = user_info.split(',')
result = (
f'Фамилия: {data[0]}\n'
f'Имя: {data[1]}\n'
f'Отчество: {data[2]}\n'
f'Дата рождения: {data[3]}\n'
f'Запрошенная сумма: {data[4]}'
)
return result
43 changes: 38 additions & 5 deletions tasks/practice3/practice3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import csv
import re
from pathlib import Path
from typing import Dict, Any, List, Optional

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

# пиши свой код здесь
words = re.split('[ .,:!?\n]', text)

return {}
for i in range(0, len(words)):
words[i] = words[i].lower()

words_count = {}

for word in words:
if re.match('^[a-zA-Z]+$', word):
if word not in words_count:
words_count[word] = 1
else:
words_count[word] += 1

return words_count


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

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

return []
new_numbers = [number**exp for number in numbers]
return new_numbers


def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float:
Expand All @@ -58,6 +73,14 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str])
:return: размер кешбека
"""

# пиши свой код здесь
result = 0
for operation in operations:
if operation['category'] in special_category:
result += operation['amount'] * 0.05
else:
result += operation['amount'] * 0.01

return result


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

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

return 0
result_set = set()
with open(get_path_to_file(), 'r') as csvfile:
reader = csv.reader(csvfile)
headers = next(reader)
column = 0
for i in range(0, len(headers)):
if headers[i] == header:
column = i
for row in reader:
result_set.add(row[column])

return len(result_set)
16 changes: 15 additions & 1 deletion 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, dict):
if 'name' in content and content['name'] == name:
return content['phone']
else:
for key, value in content.items():
phone_number = search_phone(value, name)
if phone_number is not None:
return phone_number
return None
elif isinstance(content, list):
for structure in content:
phone_number = search_phone(structure, name)
if phone_number is not None:
return phone_number
return None
return None
20 changes: 20 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):
"""

# пиши свой код здесь
if 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 @@ -56,6 +62,16 @@ def __eq__(self, other: object) -> bool:
"""

# пиши свой код здесь
if isinstance(other, Employee):
try:
if get_position_level(other.position) == get_position_level(self.position):
return True
else:
return False
except NoSuchPositionError:
raise ValueError
else:
raise TypeError

def __str__(self):
"""
Expand All @@ -64,6 +80,7 @@ def __str__(self):
"""

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

def __hash__(self):
return id(self)
Expand All @@ -83,6 +100,8 @@ 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 +117,4 @@ def __init__(self, name: str, salary: int):
"""

# пиши свой код здесь
super().__init__(name, self.position, 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,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 @@ -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.position)
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,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)}'