Skip to content

22ПИ-3 Атаев #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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 @@ -23,5 +23,5 @@ def calculate_salary(total_compensation: int) -> float:
"""

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

result = total_compensation * 0.87
return result
21 changes: 18 additions & 3 deletions tasks/practice2/practice2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Iterable
from random import uniform

UNCULTURED_WORDS = ('kotleta', 'pirog')

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

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


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

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


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

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

return len(phone_number) == 12 and phone_number[:2] == "+7" and phone_number[2:].isnumeric()


def is_amount_correct(current_amount: float, transfer_amount: str) -> bool:
Expand All @@ -59,7 +63,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,6 +82,10 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str:
"""

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


Expand All @@ -101,4 +109,11 @@ 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
31 changes: 26 additions & 5 deletions tasks/practice3/practice3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
from typing import Dict, Any, List, Optional
import csv


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

# пиши свой код здесь
signs = [",", ".", "!", "?"]
result = {}

return {}
filtered_text = text.strip().lower()
for sign in signs:
filtered_text = filtered_text.replace(sign, "")

for word in filtered_text.split():
is_word = not any((letter.isdigit() or len(word) <= 1) for letter in word)
if is_word:
if word in result.keys():
result[word] += 1
else:
result[word] = 1

return result


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

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

return []
return [pow(item, exp) for item in numbers]


def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float:
Expand All @@ -57,7 +71,9 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str])
:param special_category: список категорий повышенного кешбека
:return: размер кешбека
"""

result = 0.0
for operation in operations:
result += operation["amount"] * (0.05 if operation["category"] in special_category else 0.01)
return result


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

# пиши свой код здесь
result = []
with open(get_path_to_file(), "r") as csv_file:
data = csv.DictReader(csv_file)
for item in data:
result.append(item[header])

return 0
return len(set(result))
12 changes: 11 additions & 1 deletion tasks/practice4/practice4.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,15 @@ def search_phone(content: Any, name: str) -> Optional[str]:
"""

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

if isinstance(content, list):
for item in content:
if result := search_phone(item, name):
return result

if isinstance(content, dict):
if content.get("name") == name:
return content.get("phone")
for value in content.values():
if result := search_phone(value, name):
return result
return None
19 changes: 18 additions & 1 deletion tasks/practice5/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ def __init__(self, name: str, position: str, salary: int):
"""

# пиши свой код здесь
self.name = name
self.position = position

if not isinstance(salary, int):
raise ValueError
self._salary = salary

def get_salary(self) -> int:
"""
Метод возвращает зарплату сотрудника.
"""

# пиши свой код здесь
return self._salary

def __eq__(self, other: object) -> bool:
"""
Expand All @@ -56,6 +63,13 @@ 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 as e:
raise ValueError from e

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

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

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

# пиши свой код здесь
super().__init__(name, self.position, salary)
19 changes: 19 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,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 @@ -52,6 +65,12 @@ def get_members(self) -> Set[Employee]:
"""

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

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

def show(self) -> None:
"""
Expand Down
Loading