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
2 changes: 2 additions & 0 deletions tasks/practice1/practice1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def concatenate_strings(a: str, b: str) -> str:
"""

# пиши свой код здесь
result = a+b

return result

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

# пиши свой код здесь
result = total_compensation*0.87

return result
36 changes: 36 additions & 0 deletions 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 = "Hello, "+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,16 @@ def is_phone_correct(phone_number: str) -> bool:
"""

# пиши код здесь
result = False
if phone_number[0] == "+" and phone_number[1] == "7":
i = 2
while i < 12:
if "0" <= phone_number[i] <= "9":
i += 1
else:
break
if i == 12:
result = True
return result


Expand All @@ -59,6 +72,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,6 +95,18 @@ def moderate_text(text: str, uncultured_words: Iterable[str]) -> str:
"""

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


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

# пиши код здесь
text = user_info.split(",")
result = ""
data = ["Фамилия: ","Имя: ","Отчество: ","Дата рождения: ","Запрошенная сумма: "]
for i in range (0, len(data)):
result = result + (data[i]+text[i])
if i != len(data)-1:
result += "\n"
return result
37 changes: 31 additions & 6 deletions tasks/practice3/practice3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
from typing import Dict, Any, List, Optional

import string
import csv

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

# пиши свой код здесь
Dict = {}
for word in text.split():
count = 0
word = word.translate(str.maketrans('', '', string.punctuation))
for symbol in word:
if symbol.isdigit() == False:
count += 1
if count == len(word) and len(word) > 1:
temporary = word.lower()
if Dict.get(temporary) != None:
Dict[temporary] += 1
else:
Dict[temporary] = 1
return Dict

return {}


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

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

return []
return numbers


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

result = 0
for i in range(len(operations)):
if operations[i]["category"] in special_category:
result += operations[i]["amount"]*0.05
else:
result += operations[i]["amount"]*0.01
return result


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

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

return 0
data = set()
with open(get_path_to_file()) as f:
reader = csv.DictReader(f)
for row in reader:
data.add(row[header])
result = len(data)
return result
35 changes: 32 additions & 3 deletions tasks/practice4/practice4.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,36 @@ def search_phone(content: Any, name: str) -> Optional[str]:
:param name: имя пользователя, у которого будем искать номер телефона
:return: номер телефона пользователя или None
"""

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

return None
if isinstance(content, list):
for element in content:
if isinstance(element, list):
return search_phone(element, name)
elif isinstance(element, dict):
if "name" in element.keys():
if element["name"] == name:
return element["phone"]
flag = False
else:
return search_phone(element, name)
if flag:
return None
elif isinstance(content, dict):
if "name" in content.keys():
if content["name"] == name:
return content["phone"]
else:
return None
else:
for element in content.values():
if isinstance(element, list):
return search_phone(element, name)
elif isinstance(element, dict):
if "name" in element.keys():
if element["name"] == name:
return element["phone"]
else:
return None
else:
return search_phone(element, name)
20 changes: 20 additions & 0 deletions tasks/practice5/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ def __init__(self, name: str, position: str, salary: int):
"""

# пиши свой код здесь
if isinstance(salary, int) and isinstance(position, str) and isinstance(name, str):
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 +64,14 @@ def __eq__(self, other: object) -> bool:
"""

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


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

# пиши свой код здесь
return 'name: '+(self.name)+' position: '+(self.position)

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

# пиши свой код здесь
super().__init__(name, self.position, salary)
22 changes: 22 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 isinstance (name, str) and isinstance (manager, Manager):
self.name = name
self.manager = manager
else:
raise ValueError
self.__members = set()

def add_member(self, member: Employee) -> None:
"""
Expand All @@ -36,6 +42,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 +54,13 @@ def remove_member(self, member: Employee) -> None:
"""

# пиши свой код здесь
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 +69,11 @@ def get_members(self) -> Set[Employee]:
"""

# пиши свой код здесь
set_members = self.__members.copy()
return set_members
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