From bf2bb5cbf8b97fe5e176b820efe1759b07fcbf30 Mon Sep 17 00:00:00 2001 From: satrn8 Date: Wed, 4 Mar 2026 01:14:12 +0300 Subject: [PATCH] tasks level1 --- 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 | 22 ++++++++++++++++++++-- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/level_1/a_user_instance.py b/level_1/a_user_instance.py index e5d0368..c654b52 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 # код писать тут + person = User("Ivan", "ivan01", 20, "88009991100") + print(f"Информация о пользователе: {person.name}, {person.username}, {person.age}, {person.phone}") diff --git a/level_1/b_student_full_name_method.py b/level_1/b_student_full_name_method.py index 14ec439..567fc73 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_1 = Student("Ivan", "Petrov", "math", 5) + full_name_student = student_1.get_full_name() + print(full_name_student) diff --git a/level_1/c_product_class.py b/level_1/c_product_class.py index 3952b66..c9efbde 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: float, weight: float): + self.name = name + self.description = description + self.price = price + self.weight = weight if __name__ == '__main__': - pass # код писать тут + property_product = Product("an apple", "An apple is a round fruit that grows on trees. It can be red, green, or yellow and tastes sweet or sour", 1, 0.5) + print(f"Информация о продукте: {property_product.name}, {property_product.description}, {property_product.price}, {property_product.weight}") diff --git a/level_1/d_bank_account_increase_balance.py b/level_1/d_bank_account_increase_balance.py index cc7a16c..30da14f 100644 --- a/level_1/d_bank_account_increase_balance.py +++ b/level_1/d_bank_account_increase_balance.py @@ -15,8 +15,12 @@ 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 # код писать тут + score = BankAccount("Petrov Ivan", 1500) + print(score.balance) + score.increase_balance(999.9) + print(score.balance) + diff --git a/level_1/e_bank_account_decrease_balance.py b/level_1/e_bank_account_decrease_balance.py index dfd4586..67b8dfb 100644 --- a/level_1/e_bank_account_decrease_balance.py +++ b/level_1/e_bank_account_decrease_balance.py @@ -10,8 +10,26 @@ 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, amount: float): + if self.balance - amount < 0: + raise ValueError("Недостаточно средств") + self.balance -= amount + if __name__ == '__main__': - pass # код писать тут + score = BankAccount("Petrov Ivan", 1500) + print(score.balance) + score.increase_balance(999.9) + print(score.balance) + score.decrease_balance(500) + print(score.balance) + score.decrease_balance(3000) + print(score.balance)