Skip to content

22ПИ-3 Шалявин #148

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

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

result = a + b
return result


Expand All @@ -23,5 +23,5 @@ def calculate_salary(total_compensation: int) -> float:
"""

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

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

# пиши код здесь
greeting = f'Здравствуй, {name}!'
return greeting


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

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


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

# пиши код здесь
result = False
if phone_number[:2] == '+7':
result = phone_number[2:].isdigit() and len(phone_number[2:]) == 10
return result


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

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


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

# пиши код здесь
result = text.strip().capitalize()
result = ' '.join(result.split())

for symbol in ['"', "'"]:
result = result.replace(symbol, "")

for word in uncultured_words:
result = result.replace(word, '#' * len(word))

result = ' '.join(result.split())

return result


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

# пиши код здесь
surname, name, middle_name, date_of_birth, requested_amount = user_info.split(',')
result = (f'Фамилия: {surname}\n'
f'Имя: {name}\n'
f'Отчество: {middle_name}\n'
f'Дата рождения: {date_of_birth}\n'
f'Запрошенная сумма: {requested_amount}')
return result
37 changes: 32 additions & 5 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,21 @@ def count_words(text: str) -> Dict[str, int]:
"""

# пиши свой код здесь
marks = "'.,;:?!"
result = {}
text = text.split()

for word in text:
word = word.lower()
for symbol in marks:
word = word.replace(symbol, "")
if word.isalpha() and len(word) > 1:
if not word in result:
result[word.lower()] = 1
else:
result[word.lower()] += 1

return {}
return result


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

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

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


def get_cashback(operations: List[Dict[str, Any]], special_category: List[str]) -> float:
Expand All @@ -58,6 +71,15 @@ 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
continue
result += operation['amount'] * 0.01

return result


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

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

return 0
with open(get_path_to_file()) as file:
r = csv.DictReader(file)
unique_elements = set()
for c in r:
unique_elements.add(c[header])
result = len(unique_elements)
return result
15 changes: 14 additions & 1 deletion tasks/practice4/practice4.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,18 @@ def search_phone(content: Any, name: str) -> Optional[str]:
"""

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

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

if isinstance(content, dict):
if content.get('name') == name:
return content.get('phone')
else:
for val in content.values():
result = search_phone(val, name)
if result:
return result
return None
18 changes: 17 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):
"""

# пиши свой код здесь
if type(salary) is int:
self.name = name
self.position = position
self._salary = salary
else:
raise ValueError

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

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

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

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

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

def __hash__(self):
return id(self)
Expand All @@ -83,7 +97,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 +113,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,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,12 @@ 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]:
"""
Expand All @@ -52,6 +64,10 @@ def get_members(self) -> Set[Employee]:
"""

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

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

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