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 @@ -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
27 changes: 26 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
import random

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,8 @@ def get_amount() -> float:
"""

# пиши код здесь
current_number = random.uniform(100, 999999)
amount = float(f"{current_number:.2f}")
return amount


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

# пиши код здесь
result = False
if phone_number[0] == "+" and len(phone_number) == 12 and phone_number[1] == "7":
result = True
for i in phone_number[1:]:
if not i.isdigit():
result = False
break
return result


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

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


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

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


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

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

import csv

def count_words(text: str) -> Dict[str, int]:
"""
Expand All @@ -27,8 +27,16 @@ def count_words(text: str) -> Dict[str, int]:
"""

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

return {}
answer = {}
text = text.lower().replace('!', '').replace('?', '').replace(',', '').replace('.', '').replace(';', '')
text = text.split()
for word in text:
if all(97 <= ord(letter) <= 122 for letter in word):
if word in answer:
answer[word] += 1
else:
answer[word] = 1
return answer


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

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

return []
result = [num ** exp for num in numbers]
return result


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

result = 0.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 +113,12 @@ def csv_reader(header: str) -> int:
"""

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

path_to_file = get_path_to_file()
file = open(path_to_file, 'r')
csvFile = csv.DictReader(file)

return 0
for row in csvFile:
result.add(row[header])
return len(result)
13 changes: 12 additions & 1 deletion tasks/practice4/practice4.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,16 @@ def search_phone(content: Any, name: str) -> Optional[str]:
"""

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

if isinstance(content, dict):
if 'name' in content and content['name'] == name:
return content.get('phone', None)
for value in content.values():
phone = search_phone(value, name)
if phone is not None:
return phone
elif isinstance(content, list):
for item in content:
phone = search_phone(item, name)
if phone is not None:
return phone
return None
17 changes: 16 additions & 1 deletion 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(position, str) or not isinstance(name, str) or 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,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 NoSuchPositionError:
raise ValueError

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

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

def __hash__(self):
return id(self)
Expand All @@ -83,7 +96,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 +112,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)
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.get_members())}"