Skip to content

22ПИ-3 Машковцева #146

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 2 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 @@ -24,4 +24,4 @@ def calculate_salary(total_compensation: int) -> float:

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

return result
return total_compensation * 0.87
43 changes: 42 additions & 1 deletion 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,6 +31,9 @@ def get_amount() -> float:
"""

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

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

return amount


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

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

result = False

if len(phone_number) == 12 and phone_number[:2] == "+7":
result = True
for x in range(2, len(phone_number)):
if not phone_number[x].isdigit():
result = False

return result


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

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

result = False

if current_amount >= float(transfer_amount):
result = True

return result


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

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

return text


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

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

info = user_info.split(',')
surname = info[0]
name = info[1]
patronymic = info[2]
date = info[3]
sum = info[4]

result = (f"Фамилия: {surname}\n" +
f"Имя: {name}\n" +
f"Отчество: {patronymic}\n" +
f"Дата рождения: {date}\n" +
f"Запрошенная сумма: {sum}")

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

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

# пиши свой код здесь
words = text.split()
dictionary = {}
for word in words:
if any(x.isdigit() for x in word):
continue
w = ""
for letter in word:
if letter.isalpha():
w += letter.lower()

return {}
if w != "":
if w in dictionary:
dictionary[w] += 1
else:
dictionary[w] = 1

return dictionary


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

# пиши свой код здесь
for x in range(len(numbers)):
numbers[x] = numbers[x] ** exp

return []
return numbers


def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float:
Expand All @@ -57,6 +75,13 @@ def get_cashback(operations: List[Dict[str, Any]], special_category: List[str])
:param special_category: список категорий повышенного кешбека
: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 +125,12 @@ def csv_reader(header: str) -> int:
"""

# пиши свой код здесь
path = get_path_to_file()
result = set()

with open(path, 'r') as f:
read = csv.DictReader(f)
for x in read:
result.add(x[header])

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

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

if isinstance(content, list):
for cont in content:
phone = search_phone(cont, name)
if phone:
return phone

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

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

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

if not (isinstance(name, str) and isinstance(position, str) and 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 +64,16 @@ def __eq__(self, other: object) -> bool:
"""

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

def __str__(self):
"""
Expand All @@ -65,6 +83,8 @@ def __str__(self):

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

return 'name: ' + self.name + ' position: ' + self.position

def __hash__(self):
return id(self)

Expand All @@ -83,6 +103,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 +120,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 @@ -29,6 +29,10 @@ 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 @@ -37,13 +41,25 @@ 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:
"""
Задача: реализовать метод удаления участника из команды.
Если в команде нет такого участника поднимается исключение `NoSuchMemberError`
"""

# пиши свой код здесь
if isinstance(member, Employee):
if member in self.__members:
self.__members.remove(member)
else:
raise NoSuchMemberError(self.name, member)
else:
raise TypeError

def get_members(self) -> Set[Employee]:
"""
Expand All @@ -52,6 +68,10 @@ def get_members(self) -> Set[Employee]:
"""

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

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

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