From 85f42d5f9dc4e5292994b4ccfef38f0fe11bb558 Mon Sep 17 00:00:00 2001 From: VladimirFalkov Date: Sun, 26 Nov 2023 18:44:52 +0300 Subject: [PATCH 1/3] solutions for oop week1 level1 --- level_1/a_user_instance.py | 4 +++- level_1/b_student_full_name_method.py | 5 ++++- level_1/c_product_class.py | 12 ++++++++++-- level_1/d_bank_account_increase_balance.py | 7 +++++-- level_1/e_bank_account_decrease_balance.py | 18 ++++++++++++++++-- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/level_1/a_user_instance.py b/level_1/a_user_instance.py index e5d0368..b9b402b 100644 --- a/level_1/a_user_instance.py +++ b/level_1/a_user_instance.py @@ -14,5 +14,7 @@ def __init__(self, name: str, username: str, age: int, phone: str): if __name__ == '__main__': - pass # код писать тут + user1 = User('Зинаида', 'zinatut', 23, '+12023456789') + print(f'Информация о пользователе: {user1.name}, {user1.username}, {user1.age}, {user1.phone}.') + diff --git a/level_1/b_student_full_name_method.py b/level_1/b_student_full_name_method.py index 14ec439..e773a62 100644 --- a/level_1/b_student_full_name_method.py +++ b/level_1/b_student_full_name_method.py @@ -18,5 +18,8 @@ def get_full_name(self): if __name__ == '__main__': - pass # код писать тут + student1 = Student("Толя", "Пупкин", "Мичуренец",123) + student1.get_full_name() + name = student1.get_full_name() + print(name) diff --git a/level_1/c_product_class.py b/level_1/c_product_class.py index 3952b66..147fa3c 100644 --- a/level_1/c_product_class.py +++ b/level_1/c_product_class.py @@ -9,8 +9,16 @@ class Product: - pass # код писать тут + def __init__(self, name: str, description: str, price: float, weight:float): + self.name = name + self.desciption = description + self.price = price + self.weight = weight + + if __name__ == '__main__': - pass # код писать тут + product1 = Product('Sofa', 'Not new but comfartable', 125.7, 65.9) + print(f'Информация о продукте: {product1.name}, {product1.desciption}, ${product1.price}, {product1.weight}kg') + diff --git a/level_1/d_bank_account_increase_balance.py b/level_1/d_bank_account_increase_balance.py index cc7a16c..8cb0cee 100644 --- a/level_1/d_bank_account_increase_balance.py +++ b/level_1/d_bank_account_increase_balance.py @@ -15,8 +15,11 @@ 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 # код писать тут + your_account = BankAccount('Zina Netikova', 99.99) + print(your_account.balance) + your_account.increase_balance(99.99) + print(your_account.balance) diff --git a/level_1/e_bank_account_decrease_balance.py b/level_1/e_bank_account_decrease_balance.py index dfd4586..8458630 100644 --- a/level_1/e_bank_account_decrease_balance.py +++ b/level_1/e_bank_account_decrease_balance.py @@ -10,8 +10,22 @@ 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, outcome: float): + if self.balance - outcome > 0: + self.balance -= outcome + else: + raise ValueError if __name__ == '__main__': - pass # код писать тут + your_account = BankAccount('Kolya Pupkin', 29.99) + your_account.decrease_balance(9) + print(your_account.balance) + your_account.decrease_balance(29) \ No newline at end of file From 4a851f5d02c14d4d419b9ee5e72463ce65fb4d26 Mon Sep 17 00:00:00 2001 From: VladimirFalkov Date: Tue, 28 Nov 2023 21:25:11 +0300 Subject: [PATCH 2/3] changed because review --- level_1/a_user_instance.py | 9 ++++++--- level_1/b_student_full_name_method.py | 5 ++--- level_1/c_product_class.py | 14 +++++++------- level_1/d_bank_account_increase_balance.py | 4 ++-- level_1/e_bank_account_decrease_balance.py | 10 +++++----- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/level_1/a_user_instance.py b/level_1/a_user_instance.py index b9b402b..60e5607 100644 --- a/level_1/a_user_instance.py +++ b/level_1/a_user_instance.py @@ -12,9 +12,12 @@ def __init__(self, name: str, username: str, age: int, phone: str): self.age = age self.phone = phone + def __str__(self): + return f"Информация о пользователе: {self.name}, {self.username}, {self.age}, {self.phone}" -if __name__ == '__main__': - user1 = User('Зинаида', 'zinatut', 23, '+12023456789') - print(f'Информация о пользователе: {user1.name}, {user1.username}, {user1.age}, {user1.phone}.') +if __name__ == "__main__": + user1 = User("Зинаида", "zinatut", 23, "+12023456789") + +print(user1) diff --git a/level_1/b_student_full_name_method.py b/level_1/b_student_full_name_method.py index e773a62..274c9c5 100644 --- a/level_1/b_student_full_name_method.py +++ b/level_1/b_student_full_name_method.py @@ -17,9 +17,8 @@ def get_full_name(self): return f"Student's full name: {self.surname}, {self.name}" -if __name__ == '__main__': - student1 = Student("Толя", "Пупкин", "Мичуренец",123) +if __name__ == "__main__": + student1 = Student("Толя", "Пупкин", "Мичуренец", 123) student1.get_full_name() name = student1.get_full_name() print(name) - diff --git a/level_1/c_product_class.py b/level_1/c_product_class.py index 147fa3c..4e65158 100644 --- a/level_1/c_product_class.py +++ b/level_1/c_product_class.py @@ -9,16 +9,16 @@ class Product: - def __init__(self, name: str, description: str, price: float, weight:float): + def __init__(self, name: str, description: str, price: float, weight: float): self.name = name - self.desciption = description + self.description = description self.price = price self.weight = weight - - + def __str__(self): + return f"Информация о продукте: {product1.name}, {product1.description}, ${product1.price}, {product1.weight}kg" -if __name__ == '__main__': - product1 = Product('Sofa', 'Not new but comfartable', 125.7, 65.9) - print(f'Информация о продукте: {product1.name}, {product1.desciption}, ${product1.price}, {product1.weight}kg') +if __name__ == "__main__": + product1 = Product("Sofa", "Not new but comfortable", 125.7, 65.9) + print(product1) diff --git a/level_1/d_bank_account_increase_balance.py b/level_1/d_bank_account_increase_balance.py index 8cb0cee..eabe359 100644 --- a/level_1/d_bank_account_increase_balance.py +++ b/level_1/d_bank_account_increase_balance.py @@ -18,8 +18,8 @@ def increase_balance(self, income: float): self.balance += income -if __name__ == '__main__': - your_account = BankAccount('Zina Netikova', 99.99) +if __name__ == "__main__": + your_account = BankAccount("Zina Netikova", 99.99) print(your_account.balance) your_account.increase_balance(99.99) print(your_account.balance) diff --git a/level_1/e_bank_account_decrease_balance.py b/level_1/e_bank_account_decrease_balance.py index 8458630..104ae7d 100644 --- a/level_1/e_bank_account_decrease_balance.py +++ b/level_1/e_bank_account_decrease_balance.py @@ -16,16 +16,16 @@ def __init__(self, owner_full_name: str, balance: float): def increase_balance(self, income: float): self.balance += income - + def decrease_balance(self, outcome: float): - if self.balance - outcome > 0: + if self.balance > outcome: self.balance -= outcome else: raise ValueError -if __name__ == '__main__': - your_account = BankAccount('Kolya Pupkin', 29.99) +if __name__ == "__main__": + your_account = BankAccount("Kolya Pupkin", 29.99) your_account.decrease_balance(9) print(your_account.balance) - your_account.decrease_balance(29) \ No newline at end of file + your_account.decrease_balance(29) From 38fe9b741ebb2adccdf107fb24c9a172ad5ed3ce Mon Sep 17 00:00:00 2001 From: VladimirFalkov Date: Fri, 1 Dec 2023 10:47:51 +0300 Subject: [PATCH 3/3] fix mistakes --- level_1/c_product_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/level_1/c_product_class.py b/level_1/c_product_class.py index 4e65158..7fb6bae 100644 --- a/level_1/c_product_class.py +++ b/level_1/c_product_class.py @@ -16,7 +16,7 @@ def __init__(self, name: str, description: str, price: float, weight: float): self.weight = weight def __str__(self): - return f"Информация о продукте: {product1.name}, {product1.description}, ${product1.price}, {product1.weight}kg" + return f"Информация о продукте: {self.name}, {self.description}, ${self.price}, {self.weight}kg" if __name__ == "__main__":