From 29bdeead11810afaa8f74a4aa81fc417a863cf9c Mon Sep 17 00:00:00 2001 From: Beloded1 Date: Fri, 24 Nov 2023 14:39:47 +0400 Subject: [PATCH 1/3] Did first task --- level_1/a_user_instance.py | 4 ++-- level_1/b_student_full_name_method.py | 5 +++-- level_1/c_product_class.py | 14 ++++++++++-- level_1/d_bank_account_increase_balance.py | 12 ++++++++-- level_1/e_bank_account_decrease_balance.py | 26 ++++++++++++++++++++-- 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/level_1/a_user_instance.py b/level_1/a_user_instance.py index e5d0368..c34317e 100644 --- a/level_1/a_user_instance.py +++ b/level_1/a_user_instance.py @@ -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}") \ No newline at end of file diff --git a/level_1/b_student_full_name_method.py b/level_1/b_student_full_name_method.py index 14ec439..18b925d 100644 --- a/level_1/b_student_full_name_method.py +++ b/level_1/b_student_full_name_method.py @@ -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) \ No newline at end of file diff --git a/level_1/c_product_class.py b/level_1/c_product_class.py index 3952b66..916e6a1 100644 --- a/level_1/c_product_class.py +++ b/level_1/c_product_class.py @@ -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) + \ No newline at end of file diff --git a/level_1/d_bank_account_increase_balance.py b/level_1/d_bank_account_increase_balance.py index 0ea36f2..9fa05af 100644 --- a/level_1/d_bank_account_increase_balance.py +++ b/level_1/d_bank_account_increase_balance.py @@ -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}") diff --git a/level_1/e_bank_account_decrease_balance.py b/level_1/e_bank_account_decrease_balance.py index dfd4586..1a11f34 100644 --- a/level_1/e_bank_account_decrease_balance.py +++ b/level_1/e_bank_account_decrease_balance.py @@ -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) From 486fe7e5719cb333035792c8ed18e87508c455df Mon Sep 17 00:00:00 2001 From: Beloded1 Date: Tue, 28 Nov 2023 13:49:39 +0400 Subject: [PATCH 2/3] Finished level_2 --- level_2/a_user_from_functions_to_class.py | 11 ++++++++++- level_2/b_user_should_be_banned.py | 10 +++++++++- requirements.txt | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/level_2/a_user_from_functions_to_class.py b/level_2/a_user_from_functions_to_class.py index 18a64ce..7306f43 100644 --- a/level_2/a_user_from_functions_to_class.py +++ b/level_2/a_user_from_functions_to_class.py @@ -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' diff --git a/level_2/b_user_should_be_banned.py b/level_2/b_user_should_be_banned.py index 3ec9359..f686eda 100644 --- a/level_2/b_user_should_be_banned.py +++ b/level_2/b_user_should_be_banned.py @@ -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" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a4b4635 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +ipython == 8.18.1 \ No newline at end of file From 5832b208940e817a41282d8267a826dd2f1bfb3b Mon Sep 17 00:00:00 2001 From: Beloded1 Date: Tue, 28 Nov 2023 16:38:43 +0400 Subject: [PATCH 3/3] Finished level_3 --- level_3/a_credit_bank_account.py | 39 ++++++++++++++++++++------ level_3/b_user_manage.py | 47 ++++++++++++++++++++++++++++++-- level_3/c_text_processor.py | 14 ++++++++-- level_3/d_alcohol_product.py | 9 ++++-- 4 files changed, 94 insertions(+), 15 deletions(-) diff --git a/level_3/a_credit_bank_account.py b/level_3/a_credit_bank_account.py index b73657a..335806a 100644 --- a/level_3/a_credit_bank_account.py +++ b/level_3/a_credit_bank_account.py @@ -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()) diff --git a/level_3/b_user_manage.py b/level_3/b_user_manage.py index 6417c77..6c3d857 100644 --- a/level_3/b_user_manage.py +++ b/level_3/b_user_manage.py @@ -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()) \ No newline at end of file diff --git a/level_3/c_text_processor.py b/level_3/c_text_processor.py index d9aed49..a8d15c1 100644 --- a/level_3/c_text_processor.py +++ b/level_3/c_text_processor.py @@ -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()) diff --git a/level_3/d_alcohol_product.py b/level_3/d_alcohol_product.py index 49065b1..645f667 100644 --- a/level_3/d_alcohol_product.py +++ b/level_3/d_alcohol_product.py @@ -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())