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 @@ -10,7 +10,7 @@ def concatenate_strings(a: str, b: str) -> str:

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

return result
return a + b


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

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

return result
return total_compensation * 0.87
28 changes: 23 additions & 5 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,7 +14,7 @@ def greet_user(name: str) -> str:
"""

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


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

# пиши код здесь
return amount
return float(random.randint(100, 1000000))


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

# пиши код здесь
return result
if phone_number[:2] != "+7":
return False
for x in phone_number[2:]:
if x not in "0123456789":
return False
return True


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

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


def moderate_text(text: str, uncultured_words: Iterable[str]) -> str:
Expand All @@ -78,7 +84,14 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str:
"""

# пиши код здесь
return result
word_list = text.lower().replace("\'", "").replace("\"", "").strip().split()
result = word_list[0]
for word in word_list[1:]:
result += " " + word
for nword in uncultured_words:
if nword in result:
result = result.replace(nword, '#' * len(nword))
return result.replace(result[0], result[0].upper())


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

# пиши код здесь
fields = ["Фамилия: ", "Имя: ", "Отчество: ", "Дата рождения: ", "Запрошенная сумма: "]
data = user_info.split(',')
for i in range(len(fields)):
fields[i] += data[i]
result = "\n".join(fields)
return result
39 changes: 33 additions & 6 deletions tasks/practice3/practice3.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,19 @@ def count_words(text: str) -> Dict[str, int]:
"""

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

return {}
import string
for i in string.punctuation:
text = text.replace(i, " ")
word_list = text.split()
result = dict()
for word in word_list:
word = word.lower()
if len(word) != 0 and all(c.isalpha() for c in word):
if word in result:
result[word] += 1
else:
result[word] = 1
return result


def exp_list(numbers: List[int], exp: int) -> List[int]:
Expand All @@ -42,7 +53,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 +69,12 @@ 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 @@ -99,6 +116,16 @@ def csv_reader(header: str) -> int:
:return: количество уникальных элементов в столбце
"""

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

return 0
import csv
with open(get_path_to_file(), mode='r') as file:
csvfile = csv.reader(file, delimiter=",")
flag = True
res_list = []
for row in csvfile:
if flag:
header_index = row.index(header)
else:
res_list.append(row[header_index])
flag = False
result = len(dict.fromkeys(res_list))
return result
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, dict):
if 'name' in content.keys() and 'phone' in content.keys():
if content['name'] == name:
return content['phone']
for key in content.values():
result = search_phone(key, name)
if result is not None:
return result
elif isinstance(content, list):
for item in content:
result = search_phone(item, name)
if result is not None:
return result
return None
19 changes: 19 additions & 0 deletions tasks/practice5/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@ 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 +65,12 @@ def __eq__(self, other: object) -> bool:
"""

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

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

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

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

# пиши свой код здесь
super().__init__(name, self.position, salary)
23 changes: 23 additions & 0 deletions tasks/practice5/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def __init__(self, name: str, manager: Manager):
"""

# пиши свой код здесь
if not isinstance(manager, Manager):
raise TypeError

self.name = name
self.manager = manager
self.__members = set()

def add_member(self, member: Employee) -> None:
"""
Expand All @@ -37,6 +43,10 @@ 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 @@ -45,6 +55,13 @@ def remove_member(self, member: Employee) -> None:

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

if not isinstance(member, Employee):
raise TypeError
try:
self.__members.remove(member)
except KeyError as e:
raise NoSuchMemberError(self.name, member) from e

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

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

result = self.__members.copy()
return result

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

def show(self) -> None:
"""
DO NOT EDIT!
Expand Down