From 15d671f6fc458d313289bcc6495821162870ee20 Mon Sep 17 00:00:00 2001 From: Mark Proskurin Date: Fri, 8 Sep 2023 13:08:38 +0300 Subject: [PATCH] level_1 is done --- .gitignore | 1 + level_1/a_user_instance.py | 3 ++- level_1/b_student_full_name_method.py | 5 +++-- level_1/c_product_class.py | 9 +++++++-- level_1/d_bank_account_increase_balance.py | 8 +++++--- level_1/e_bank_account_decrease_balance.py | 23 ++++++++++++++++++++-- 6 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eba74f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +venv/ \ No newline at end of file diff --git a/level_1/a_user_instance.py b/level_1/a_user_instance.py index e5d0368..6acf36b 100644 --- a/level_1/a_user_instance.py +++ b/level_1/a_user_instance.py @@ -14,5 +14,6 @@ def __init__(self, name: str, username: str, age: int, phone: str): if __name__ == '__main__': - pass # код писать тут + new_user = User(name="Human", username="Towel", age=22, phone="+7(999)999-99-99") + print(f"Информация о пользователе:\nИмя - {new_user.name}.\nЛогин - {new_user.username}.\nВозраст - {new_user.age}.\nМобильный телефон - {new_user.phone}.") diff --git a/level_1/b_student_full_name_method.py b/level_1/b_student_full_name_method.py index 14ec439..05222ea 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(name='Mark', surname='Proskurin', faculty='Python Development', course=2) + get_full_student_name = student.get_full_name() + print(get_full_student_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..2d89213 100644 --- a/level_1/c_product_class.py +++ b/level_1/c_product_class.py @@ -9,8 +9,13 @@ 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 if __name__ == '__main__': - pass # код писать тут + product = Product(name='Chair', description='Very comfortable office chair', price='300$', weight=22) + print(f"Information about product:\nName - {product.name}.\nDescription - {product.description}.\nPrice - {product.price}.\nWeight - {product.weight} lb. ") diff --git a/level_1/d_bank_account_increase_balance.py b/level_1/d_bank_account_increase_balance.py index 0ea36f2..401cfec 100644 --- a/level_1/d_bank_account_increase_balance.py +++ b/level_1/d_bank_account_increase_balance.py @@ -15,8 +15,10 @@ def __init__(self, owner_full_name: str, balance: float): self.balance = balance def increase_balance(self, income: float): - pass # код писать тут - + self.balance += income if __name__ == '__main__': - pass # код писать тут + bank_account = BankAccount(owner_full_name='User Name', balance=1200.91) + print(f'Баланс счёта: {bank_account.balance}') + bank_account.increase_balance(259.22) + print(f'Ваш баланс после пополнения: {bank_account.balance}') diff --git a/level_1/e_bank_account_decrease_balance.py b/level_1/e_bank_account_decrease_balance.py index dfd4586..11aede1 100644 --- a/level_1/e_bank_account_decrease_balance.py +++ b/level_1/e_bank_account_decrease_balance.py @@ -10,8 +10,27 @@ 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 + + def decrease_balance(self, expense: float): + if self.balance - expense < 0: + raise ValueError('На вашем счёте недостаточно средств') + self.balance -= expense if __name__ == '__main__': - pass # код писать тут + account = BankAccount('Name User', 1000.0) + account.decrease_balance(500) + print(f'Баланс после снятия средств: {account.balance}') + + try: + account.decrease_balance(2000) + except ValueError as e: + print(f'Ошибка: {e}') + + print(f'Баланс после неудачной попытки снятия средств: {account.balance}')