Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
29bdeea
Did first task
alexandrbeloded Nov 24, 2023
a39b65f
Merge pull request #1 from Beloded1/level_1
Beloded1 Nov 24, 2023
486fe7e
Finished level_2
alexandrbeloded Nov 28, 2023
650bd98
Merge pull request #2 from Beloded1/level_2
Beloded1 Nov 28, 2023
5832b20
Finished level_3
alexandrbeloded Nov 28, 2023
647c35f
Merge pull request #3 from Beloded1/level_3
Beloded1 Nov 28, 2023
ff3e915
Add setup.cfg
alexandrbeloded Dec 4, 2023
74e6378
Merge pull request #4 from Beloded1/level_4
Beloded1 Dec 4, 2023
378646f
Did 'a' task but it doesn't work properly.
alexandrbeloded Dec 5, 2023
8569c8e
Merge pull request #5 from Beloded1/level_4.v2
Beloded1 Dec 5, 2023
0c06c30
Finished level_4
alexandrbeloded Dec 6, 2023
789a3b2
Merge pull request #6 from Beloded1/level_4.v3
Beloded1 Dec 6, 2023
ad5d13b
corrected annotation types
alexandrbeloded Dec 7, 2023
edcba73
a done
alexandrbeloded Dec 7, 2023
53d1fe4
b done
alexandrbeloded Dec 7, 2023
c5a4243
c done
alexandrbeloded Dec 7, 2023
1957929
d done
alexandrbeloded Dec 7, 2023
48295b2
Merge pull request #7 from Beloded1/level_5
Beloded1 Dec 7, 2023
66ee16b
'a' done
alexandrbeloded Dec 14, 2023
7da8243
'b' done
alexandrbeloded Dec 14, 2023
cc73f24
Merge pull request #8 from Beloded1/level_6
Beloded1 Dec 14, 2023
76163b7
'a', 'b' done
alexandrbeloded Dec 14, 2023
a9a016c
'c' done
alexandrbeloded Dec 15, 2023
d884d04
'd' done
alexandrbeloded Dec 15, 2023
027f9a1
'e' done
alexandrbeloded Dec 15, 2023
9261499
'f' done
alexandrbeloded Dec 15, 2023
a270b50
'f' done
alexandrbeloded Dec 15, 2023
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
Binary file added code.deb
Binary file not shown.
4 changes: 2 additions & 2 deletions level_1/a_user_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def __init__(self, name: str, username: str, age: int, phone: str):


if __name__ == '__main__':
pass # код писать тут

user = User('Alexandr', 'Beloded', 35, '8927111111')
print (f"Информация о пользователе: имя: {user.name}, юзернэйм: {user.username}, возраст: {user.age}, телефон: {user.phone}")
5 changes: 3 additions & 2 deletions level_1/b_student_full_name_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ def get_full_name(self):


if __name__ == '__main__':
pass # код писать тут

student = Student('OLeg', 'Ivanov', 'IT', 3)
full_name = student.get_full_name()
print(full_name)
14 changes: 12 additions & 2 deletions level_1/c_product_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,18 @@


class Product:
pass # код писать тут
def __init__(self, name: str, description: str, price: int, weight: int):
self.name = name
self.description = description
self.price = price
self.weight = weight

def info_about_product(self):
return f'Data about product: {self.name}, {self.description}, {self.price}, {self.weight}'


if __name__ == '__main__':
pass # код писать тут
phone = Product('IPhone', '15 Pro', 1100, 195)
info = phone.info_about_product()
print(info)

12 changes: 10 additions & 2 deletions level_1/d_bank_account_increase_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ def __init__(self, owner_full_name: str, balance: float):
self.balance = balance

def increase_balance(self, income: float):
pass # код писать тут
self.balance += income
return self.balance

def info_bank_account(self):
return f'{self.owner_full_name}, {self.balance} '


if __name__ == '__main__':
pass # код писать тут
user_acc = BankAccount('Oleg Ivanov', 500.0)
info = user_acc.info_bank_account()
print(info)
user_acc.increase_balance(1000.0)
print(f"Баланс счета после пополнения: {user_acc.balance}")
26 changes: 24 additions & 2 deletions level_1/e_bank_account_decrease_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,30 @@


class BankAccount:
pass # код писать тут
def __init__(self, owner_full_name: str, balance: float):
self.owner_full_name = owner_full_name
self.balance = balance

def increase_balance(self, income: float):
self.balance += income
return self.balance

def decrease_balance(self, outcome: float):
if self.balance - outcome < 0:
raise ValueError("You can't receive more than you have")
self.balance -= outcome
return self.balance

def info_bank_account(self):
return f'{self.owner_full_name}, {self.balance} '


if __name__ == '__main__':
pass # код писать тут
user_acc = BankAccount('Oleg Ivanov', 1000.5)
print(f"Баланс счета до снятия: {user_acc.balance}")
user_acc.decrease_balance(500.5)
print(f"Баланс счета после снятия 500: {user_acc.balance}")
try:
user_acc.decrease_balance(100000)
except ValueError as e:
print(e)
11 changes: 10 additions & 1 deletion level_2/a_user_from_functions_to_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ def generate_short_user_description(username: str, user_id: int, name: str):


class User:
pass # код писать тут
def __init__(self, username: str, user_id: int, name: str) -> None:
self.username = username
self.user_id = user_id
self.name = name

def make_username_capitalized(self) -> str:
return self.username.capitalize()

def generate_short_user_description(self) -> str:
return f'User with id {self.user_id} has {self.username} username and {self.name} name'
10 changes: 9 additions & 1 deletion level_2/b_user_should_be_banned.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@


class User:
pass # код писать тут
def __init__(self, name: str, surname: str, age: int) -> None:
self.name = name
self.surname = surname
self.age = age

def should_be_banned(self):
if self.surname in SURNAMES_TO_BAN:
return f"{self.surname} is banned"
return f"{self.surname} is not banned"
39 changes: 30 additions & 9 deletions level_3/a_credit_bank_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,45 @@
4. Создать экземпляр класс CreditAccount и вызвать у него каждый из возможных методов.
"""

# код писать тут


class CreditAccount:
def __init__(self, owner_full_name: str, balance: float):
class BankAccount:
def __init__(self, owner_full_name: str, balance: float) -> None:
self.owner_full_name = owner_full_name
self.balance = balance

def increase_balance(self, amount: float):

class CreditAccount(BankAccount):
def increase_balance(self, amount: float) -> float:
self.balance += amount

def decrease_balance(self, amount: float):
def decrease_balance(self, amount: float) -> float:
self.balance -= amount

def is_eligible_for_credit(self):
def is_eligible_for_credit(self) -> bool:
return self.balance > 1000
# class CreditAccount:
# def __init__(self, owner_full_name: str, balance: float):
# self.owner_full_name = owner_full_name
# self.balance = balance

# def increase_balance(self, amount: float):
# self.balance += amount

if __name__ == '__main__':
pass # код писать тут
# def decrease_balance(self, amount: float):
# self.balance -= amount

# def is_eligible_for_credit(self):
# return self.balance > 1000


if __name__ == '__main__':
owner_1 = BankAccount('ALexandr Ivanov', 1500.00)
print(owner_1.owner_full_name)
print(owner_1.balance)
owner_2 = CreditAccount('Oleg Olegov', 1000.00)
print(owner_2.owner_full_name)
print(owner_2.balance)
owner_2.increase_balance(300.00)
print(owner_2.balance)
owner_2.decrease_balance(100.00)
print(owner_2.is_eligible_for_credit())
47 changes: 45 additions & 2 deletions level_3/b_user_manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,52 @@ def get_users(self):
return self.usernames


# код писать тут
class AdminManager(UserManager):
def ban_username(self, username: str) -> bool:
if username in self.usernames:
self.usernames.remove(username)
return True
else:
print(f"Такого пользователя не существует.")
return False


class SuperAdminManager(AdminManager):
def ban_all_users(self) -> None: # функция не работает.
self.usernames = []


if __name__ == '__main__':
pass # код писать тут
user_manager = UserManager()

# Добавляем пользователей
user_manager.add_user("Ivan")
user_manager.add_user("Aleksey")
user_manager.add_user("Oleg")

# Выводим список пользователей
print("Список пользователей (UserManager):", user_manager.get_users())

# Создаем экземпляр класса AdminManager
admin_manager = AdminManager()

# Наследуем список пользователей от UserManager
admin_manager.usernames = user_manager.usernames # Механизм наследования!!!

# Забанить пользователя
admin_manager.ban_username("Aleksey")

# Выводим обновленный список пользователей
print("Список пользователей (AdminManager):", admin_manager.get_users())

# Создаем экземпляр класса SuperAdminManager
super_admin_manager = SuperAdminManager()

# Наследуем список пользователей от AdminManager
super_admin_manager.usernames = admin_manager.usernames # Механизм наследования!!!

# Забанить всех пользователей
super_admin_manager.ban_all_users()

# Выводим обновленный список пользователей
print("Список пользователей (SuperAdminManager):", super_admin_manager.get_users())
14 changes: 12 additions & 2 deletions level_3/c_text_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ def summarize(self):
return f'Total text length: {len(self.text)}'


# код писать тут
class AdvancedTextProcessor(TextProcessor):
def summarize(self):
return f'Total text length: {len(self.text)}, total number of words in the text: {sum(1 for x in self.text.split())}'


if __name__ == '__main__':
pass # код писать тут
text_1 = TextProcessor('Today is a difficult day for all of us')
print(text_1.text)
print(text_1.to_upper())
print(text_1.summarize())
text_2 = AdvancedTextProcessor('Tomorrow will be much more difficult than today')
print(text_2.text)
print(text_2.to_upper())
print(text_2.summarize())
print(text_1.summarize())
9 changes: 7 additions & 2 deletions level_3/d_alcohol_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ def is_available(self):


class AlcoholProduct(Product):
pass # код писать тут
def is_available(self):
return super().is_available() and 23 > datetime.now().hour > 5


if __name__ == '__main__':
pass # код писать тут
cool_beer = AlcoholProduct('Zchigulevskoe', 72, 100)
print(cool_beer.price)
print(cool_beer.title)
print(cool_beer.stock_quantity)
print(cool_beer.is_available())
22 changes: 17 additions & 5 deletions level_4/a_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,36 @@
"""
import csv
import json
from typing import Any


class FileHandler:
def __init__(self, filename):
def __init__(self, filename: str) -> None:
self.filename = filename

def read(self):
def read(self) -> str | list[dict[str | Any, str | Any]]:
with open(self.filename, 'r') as file:
return file.read()


class JSONHandler(FileHandler):
pass # код писать тут
def read(self) -> str:
with open(self.filename, 'r') as json_file:
return json.load(json_file)


class CSVHandler(FileHandler):
pass # код писать тут
def read(self) -> list[dict[str | Any, str | Any]]:
with open(self.filename, 'r') as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter=',')
return [row for row in csv_reader]


if __name__ == '__main__':
pass # код писать тут

file_reader = FileHandler('data/text.txt')
print(file_reader.read())
json_reader = JSONHandler('data/recipes.json')
print(json_reader.read())
csv_reader = CSVHandler('data/user_info.csv')
print(csv_reader.read())
28 changes: 23 additions & 5 deletions level_4/b_food_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,38 @@


class Product:
def __init__(self, title, quantity):
def __init__(self, title: str, quantity: int) -> None:
self.title = title
self.quantity = quantity

def get_full_info(self):
def get_full_info(self) -> str:
return f'Product {self.title}, {self.quantity} in stock.'

def is_available(self):
def is_available(self) -> bool:
return self.quantity > 0


class FoodProduct(Product):
pass # код писать тут
def __init__(self, title: str, quantity: int, expiration_date: str) -> None:
super().__init__(title, quantity)
self.expiration_date = expiration_date

def is_available(self) -> bool:
expiration_date_datetime = datetime.strptime(self.expiration_date, '%d-%m-%Y')
return super().is_available() and expiration_date_datetime > datetime.now()

def get_full_info(self) -> str:
return f'Product {self.title}, {self.quantity} in stock with {self.expiration_date} experation date.'


if __name__ == '__main__':
pass # код писать тут
product = Product('Milk', 10)
print(product.get_full_info())
print(product.is_available())
drink_product = FoodProduct('Vodka', 100, '22-12-2023')
print(drink_product.get_full_info())
print(drink_product.is_available())
drink_product_1 = FoodProduct('Not vodka', 100, '01-12-2023')
print(drink_product_1.get_full_info())
print(drink_product_1.is_available())

21 changes: 18 additions & 3 deletions level_5/a_premium_food.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,30 @@ def __init__(self, title: str, price: float):
self.title = title
self.price = price

def get_product_info(self):
def get_product_info(self) -> str:
return f'Product title: {self.title}, price: {self.price}'


class FoodProductMixin:
def is_premium_food(self):
def is_premium_food(self) -> bool:
return self.price > 10


class FoodProduct(FoodProductMixin, Product):
def __init__(self, title: str, price: float):
super().__init__(title, price)

def get_product_info(self) -> str:
return super().get_product_info() + (' (Premium)') if self.is_premium_food() else super().get_product_info()


if __name__ == '__main__':
pass # код писать тут
food_product_1 = FoodProduct('Bread', 9.0)
print(food_product_1.get_product_info())

food_product_2 = FoodProduct('Super_Bread', 99.99)
print(food_product_2.get_product_info())




Loading