From 2ddcb90a33577a4c3fcb9ddda592fb7c3b6f29fd Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Mon, 9 Sep 2024 13:41:59 +0300 Subject: [PATCH 01/15] level_1 --- level_1/a_user_instance.py | 6 ++++-- level_1/b_student_full_name_method.py | 8 +++++--- level_1/c_product_class.py | 24 +++++++++++++++++++--- level_1/d_bank_account_increase_balance.py | 9 +++++--- level_1/e_bank_account_decrease_balance.py | 20 +++++++++++++++--- pyproject.toml | 14 +++++++++++++ 6 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 pyproject.toml diff --git a/level_1/a_user_instance.py b/level_1/a_user_instance.py index e5d0368..7baa7f9 100644 --- a/level_1/a_user_instance.py +++ b/level_1/a_user_instance.py @@ -12,7 +12,9 @@ def __init__(self, name: str, username: str, age: int, phone: str): self.age = age self.phone = phone + def __str__(self) -> str: + return f"Информация о пользователе: {self.name}, {self.username}, {self.age}, {self.phone}" -if __name__ == '__main__': - pass # код писать тут +if __name__ == "__main__": + print(User("john smith", "john_smith", 35, "+78003598989")) diff --git a/level_1/b_student_full_name_method.py b/level_1/b_student_full_name_method.py index 14ec439..0be5cd2 100644 --- a/level_1/b_student_full_name_method.py +++ b/level_1/b_student_full_name_method.py @@ -12,11 +12,13 @@ def __init__(self, name: str, surname: str, faculty: str, course: int): self.surname = surname self.faculty = faculty self.course = course + self.full_name = "" def get_full_name(self): return f"Student's full name: {self.surname}, {self.name}" -if __name__ == '__main__': - pass # код писать тут - +if __name__ == "__main__": + student = Student(name="john", surname="smith", faculty="economy", course=2) + student.full_name = student.get_full_name() + print(student.full_name) diff --git a/level_1/c_product_class.py b/level_1/c_product_class.py index 3952b66..f727b38 100644 --- a/level_1/c_product_class.py +++ b/level_1/c_product_class.py @@ -9,8 +9,26 @@ class Product: - pass # код писать тут + def __init__( + self, title: str, description: str, price: float, weight: float + ) -> None: + self.title = title + self.description = description + self.price = price + self.weight = weight + def __str__(self) -> str: + return f"Информация о продукте: {self.title}, {self.description}, {self.price}, {self.weight}" -if __name__ == '__main__': - pass # код писать тут + +if __name__ == "__main__": + str1 = "Конструкция пишущего узла шариковых ручек представляет собой металлическую трубку из нержавеющей стали." + str2 = "Между ее стенками располагается маленький вольфрамовый шарик." + str3 = "Во время его движения по бумаге он «обмазывается» пастообразными чернилами со стороны стержня." + product = Product( + title="Ручка шариковая", + description=f"{str1} {str2} {str3}", + price=15.55, + weight=0.01, + ) + print(product) diff --git a/level_1/d_bank_account_increase_balance.py b/level_1/d_bank_account_increase_balance.py index cc7a16c..b8f32cc 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 # код писать тут +if __name__ == "__main__": + bank_account = BankAccount("john smith", 100.0) + print(f"Баланс: {bank_account.balance}") + bank_account.increase_balance(35.25) + 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..d62fc00 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 -if __name__ == '__main__': - pass # код писать тут + def decrease_balance(self, cost: float): + if self.balance - cost < 0: + raise ValueError("balance must be above zero") + self.balance -= cost + + +if __name__ == "__main__": + bank_account = BankAccount("john smith", 100.0) + print(f"Баланс: {bank_account.balance}") + bank_account.decrease_balance(35.25) + print(f"Баланс: {bank_account.balance}") + bank_account.decrease_balance(100.0) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..eb775f8 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,14 @@ +[tool.poetry] +name = "oop-bases-challenges" +version = "0.1.0" +description = "" +authors = ["denis sergeevich pekshev "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.12" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" \ No newline at end of file From 1a04536ba3824fe604c640c647230f38faa38102 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Mon, 9 Sep 2024 14:00:50 +0300 Subject: [PATCH 02/15] level_2 --- level_2/a_user_from_functions_to_class.py | 22 +++++++++++++++++++--- level_2/b_user_should_be_banned.py | 18 ++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/level_2/a_user_from_functions_to_class.py b/level_2/a_user_from_functions_to_class.py index 18a64ce..87975c9 100644 --- a/level_2/a_user_from_functions_to_class.py +++ b/level_2/a_user_from_functions_to_class.py @@ -1,4 +1,4 @@ -"""" +""" " У нас есть функции для работы с пользователем, но хочется работать с ним через класс. Задания: @@ -11,8 +11,24 @@ def make_username_capitalized(username: str): def generate_short_user_description(username: str, user_id: int, name: str): - return f'User with id {user_id} has {username} username and {name} name' + return f"User with id {user_id} has {username} username and {name} name" class User: - pass # код писать тут + def __init__(self, user_id: int, name: str, username: str) -> None: + self.user_id = user_id + self.name = name + self.username = username + + 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" + + +if __name__ == "__main__": + user = User(user_id=1, name="john smith", username="john smith") + print( + f"{user.name}, {user.make_username_capitalized()}, {user.generate_short_user_description()}" + ) diff --git a/level_2/b_user_should_be_banned.py b/level_2/b_user_should_be_banned.py index 3ec9359..33e8e7c 100644 --- a/level_2/b_user_should_be_banned.py +++ b/level_2/b_user_should_be_banned.py @@ -7,8 +7,22 @@ Пользователя стоит забанить, если его фамилия находится в SURNAMES_TO_BAN. """ -SURNAMES_TO_BAN = ['Vaughn', 'Wilhelm', 'Santaros', 'Porter', 'Smith'] +SURNAMES_TO_BAN = ["Vaughn", "Wilhelm", "Santaros", "Porter", "Smith"] class User: - pass # код писать тут + def __init__(self, name: str, username: str, age: int): + self.name = name + self.username = username + self.age = age + + def should_be_banned(self) -> bool: + return self.name in SURNAMES_TO_BAN + + +if __name__ == "__main__": + user1 = User(name="Smith", username="john smith", age=35) + print(f"{user1.name} should_be_banned : {user1.should_be_banned()}") + + user2 = User(name="Croft", username="lara croft", age=25) + print(f"{user2.name} should_be_banned : {user2.should_be_banned()}") From ae6a6c2b38c121fd6bbba2a64f218bebdb4460f4 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Tue, 17 Sep 2024 08:39:44 +0300 Subject: [PATCH 03/15] a_credit_bank_account.py --- level_3/a_credit_bank_account.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/level_3/a_credit_bank_account.py b/level_3/a_credit_bank_account.py index b73657a..a98b594 100644 --- a/level_3/a_credit_bank_account.py +++ b/level_3/a_credit_bank_account.py @@ -8,10 +8,8 @@ 4. Создать экземпляр класс CreditAccount и вызвать у него каждый из возможных методов. """ -# код писать тут - -class CreditAccount: +class BankAccount: def __init__(self, owner_full_name: str, balance: float): self.owner_full_name = owner_full_name self.balance = balance @@ -22,10 +20,20 @@ def increase_balance(self, amount: float): def decrease_balance(self, amount: float): self.balance -= amount + +class CreditAccount(BankAccount): def is_eligible_for_credit(self): return self.balance > 1000 -if __name__ == '__main__': - pass # код писать тут - +if __name__ == "__main__": + ba1 = BankAccount("Vasya", 1000.99) + ba1.increase_balance(548.98) + ba1.decrease_balance(125.54) + print(f"balance: {ba1.balance}") + ca1 = CreditAccount("Petya", 465.88) + ca1.increase_balance(1110.30) + ca1.decrease_balance(125.00) + print( + f"balance: {ca1.balance}, is_eligible_for_credit: {ca1.is_eligible_for_credit()}" + ) From 089eedef27f9557aa0f9454455df335db024fe2c Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Tue, 17 Sep 2024 08:51:53 +0300 Subject: [PATCH 04/15] b_user_manage.py --- level_3/b_user_manage.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/level_3/b_user_manage.py b/level_3/b_user_manage.py index 6417c77..6378d05 100644 --- a/level_3/b_user_manage.py +++ b/level_3/b_user_manage.py @@ -22,9 +22,36 @@ def get_users(self): return self.usernames -# код писать тут - - -if __name__ == '__main__': - pass # код писать тут - +class AdminManager(UserManager): + def ban_username(self, username: str): + if username not in self.get_users(): + print("Такого пользователя не существует.") + return + self.usernames.remove(username) + + +class SuperAdminManager(AdminManager): + def ban_all_users(self): + self.usernames.clear() + + +if __name__ == "__main__": + um1 = UserManager() + um1.add_user("Vasya") + um1.add_user("Petya") + um1.add_user("Slava") + + am1 = AdminManager() + am1.add_user("Vasya") + am1.add_user("Petya") + am1.add_user("Slava") + am1.ban_username("Slava") + am1.ban_username("Tolya") + + sam1 = SuperAdminManager() + sam1.add_user("Vasya") + sam1.add_user("Petya") + sam1.add_user("Slava") + sam1.ban_username("Slava") + sam1.ban_username("Tolya") + sam1.ban_all_users() From 6ae856612e1aa7d36a703d64cb9fde30ececf927 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Tue, 17 Sep 2024 09:13:35 +0300 Subject: [PATCH 05/15] c_text_processor.py --- level_3/c_text_processor.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/level_3/c_text_processor.py b/level_3/c_text_processor.py index d9aed49..0fc251e 100644 --- a/level_3/c_text_processor.py +++ b/level_3/c_text_processor.py @@ -17,11 +17,24 @@ def to_upper(self): return self.text.upper() def summarize(self): - return f'Total text length: {len(self.text)}' + return f"Total text length: {len(self.text)}" -# код писать тут - - -if __name__ == '__main__': - pass # код писать тут +class AdvancedTextProcessor(TextProcessor): + def summarize(self): + return f"Total text length: {len(self.text)}, total number of words in the text: {len(self.text.split())}" + + +if __name__ == "__main__": + some_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\ + sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\ + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\ + Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\ + Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." + tp1 = TextProcessor(some_text) + print(tp1.to_upper()) + print(tp1.summarize()) + + atp1 = AdvancedTextProcessor(some_text) + print(atp1.to_upper()) + print(atp1.summarize()) From 5d7b683371ca39889a1530c4f7ed606e0b980b82 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Tue, 17 Sep 2024 10:50:32 +0300 Subject: [PATCH 06/15] d_alcohol_product.py --- level_3/d_alcohol_product.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/level_3/d_alcohol_product.py b/level_3/d_alcohol_product.py index 49065b1..fe69f31 100644 --- a/level_3/d_alcohol_product.py +++ b/level_3/d_alcohol_product.py @@ -9,6 +9,7 @@ Для определения текущего часа можно использовать datetime.now().hour 3. Создайте экземпляр класса AlcoholProduct и проверьте, можно ли сейчас продавать алкоголь. """ + from datetime import datetime @@ -26,8 +27,10 @@ def is_available(self): class AlcoholProduct(Product): - pass # код писать тут + def is_available(self): + return super().is_available() and 5 <= datetime.now().hour <= 11 -if __name__ == '__main__': - pass # код писать тут +if __name__ == "__main__": + ap1 = AlcoholProduct("beer", 50.5, 10) + print(ap1.is_available()) From fc21603e51ae6f9e86354dde395db8615c4e11c3 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Mon, 23 Sep 2024 08:45:17 +0300 Subject: [PATCH 07/15] correct mistakes and notices --- level_3/c_text_processor.py | 4 +++- level_3/d_alcohol_product.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/level_3/c_text_processor.py b/level_3/c_text_processor.py index 0fc251e..8903060 100644 --- a/level_3/c_text_processor.py +++ b/level_3/c_text_processor.py @@ -22,7 +22,9 @@ def summarize(self): class AdvancedTextProcessor(TextProcessor): def summarize(self): - return f"Total text length: {len(self.text)}, total number of words in the text: {len(self.text.split())}" + total_text_length = len(self.text) + total_number_of_words = len(self.text.split()) + return f"Total text length: {total_text_length}, total number of words in the text: {total_number_of_words}" if __name__ == "__main__": diff --git a/level_3/d_alcohol_product.py b/level_3/d_alcohol_product.py index fe69f31..545f279 100644 --- a/level_3/d_alcohol_product.py +++ b/level_3/d_alcohol_product.py @@ -28,7 +28,8 @@ def is_available(self): class AlcoholProduct(Product): def is_available(self): - return super().is_available() and 5 <= datetime.now().hour <= 11 + available_hours = [hour for hour in range(5, 23)] + return super().is_available() and datetime.now().hour in available_hours if __name__ == "__main__": From de9d3eff581d9773ac5263c1b9910b639071175d Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Sat, 12 Oct 2024 10:10:11 +0300 Subject: [PATCH 08/15] level_6\a_log_products.py --- level_6/a_log_products.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/level_6/a_log_products.py b/level_6/a_log_products.py index d11925d..90e765c 100644 --- a/level_6/a_log_products.py +++ b/level_6/a_log_products.py @@ -10,33 +10,47 @@ """ +class PrintLoggerMixin: + def log(self, message: str): + print(message) + + class Product: def __init__(self, title: str, price: float): self.title = title self.price = price def get_info(self): - return f'Product {self.title} with price {self.price}' + return f"Product {self.title} with price {self.price}" -class PremiumProduct(Product): +class PremiumProduct(Product, PrintLoggerMixin): def increase_price(self): self.price *= 1.2 + self.log("increase_price method PremiumProduct class was called") def get_info(self): base_info = super().get_info() - return f'{base_info} (Premium)' + self.log("get_info method PremiumProduct class was called") + return f"{base_info} (Premium)" -class DiscountedProduct(Product): +class DiscountedProduct(Product, PrintLoggerMixin): def decrease_price(self): self.price /= 1.2 + self.log("decrease_price method DiscountedProduct class was called") def get_info(self): base_info = super().get_info() - return f'{base_info} (Discounted)' + self.log("get_info method DiscountedProduct class was called") + return f"{base_info} (Discounted)" -if __name__ == '__main__': - pass +if __name__ == "__main__": + pp1 = PremiumProduct("milk", 79.49) + pp1.increase_price() + print(pp1.get_info()) + dp1 = DiscountedProduct("bread", 49.99) + dp1.decrease_price() + print(dp1.get_info()) From 3aa6a5dd57fa4efaace507004fb7c6bfebd976b1 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Sat, 12 Oct 2024 10:22:38 +0300 Subject: [PATCH 09/15] level_6\b_developer.py --- level_6/b_developer.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/level_6/b_developer.py b/level_6/b_developer.py index dbe12c8..5b5d44c 100644 --- a/level_6/b_developer.py +++ b/level_6/b_developer.py @@ -16,7 +16,7 @@ def __init__(self, name: str, surname: str, age: int, salary: float): self.salary = salary def get_info(self): - return f'{self.name} with salary {self.salary}' + return f"{self.name} with salary {self.salary}" class ItDepartmentEmployee(Employee): @@ -35,9 +35,18 @@ def decrease_salary(self, employee: Employee, amount: float): employee.salary -= amount -# код писать тут +class Developer(ItDepartmentEmployee, SuperAdminMixin): + def __init__(self, name: str, surname: str, age: int, salary: float, lang: str): + super().__init__(name, surname, age, salary) + self.lang = lang + def get_info(self): + return f"{super().get_info()} by {self.lang}" -if __name__ == '__main__': - pass # код писать тут +if __name__ == "__main__": + dev = Developer("denis", "pekshev", 40, 40000.0, "python") + print(dev.get_info()) + dev.increase_salary(dev, 3000.0) + dev.decrease_salary(dev, 6000.0) + print(dev.get_info()) From 40d9aa34c36567e8c44fad3c9a6a9dac857bc808 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Sat, 12 Oct 2024 10:24:46 +0300 Subject: [PATCH 10/15] level_7\a_ebay_title.py --- level_7/a_ebay_title.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/level_7/a_ebay_title.py b/level_7/a_ebay_title.py index 3b2c42c..7b8b86f 100644 --- a/level_7/a_ebay_title.py +++ b/level_7/a_ebay_title.py @@ -7,17 +7,18 @@ то что вы ожидаете. """ -EBAY_TITLE = 'eBay' - class EbayProduct: + EBAY_TITLE = "eBay" + def __init__(self, title: str, price: float): self.title = title self.price = price def get_product_info(self): - return f'Product {self.title} with price {self.price} from {EBAY_TITLE} marketplace' + return f"Product {self.title} with price {self.price} from {self.EBAY_TITLE} marketplace" -if __name__ == '__main__': - pass +if __name__ == "__main__": + eb1 = EbayProduct("chair", 333.49) + print(eb1.get_product_info()) From 910631fb2005eb3e0086f9edcf8f83989d22f23e Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Sat, 12 Oct 2024 10:29:59 +0300 Subject: [PATCH 11/15] level_7\b_bank_account.py --- level_7/b_bank_account.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/level_7/b_bank_account.py b/level_7/b_bank_account.py index cb415e7..5a6da7d 100644 --- a/level_7/b_bank_account.py +++ b/level_7/b_bank_account.py @@ -17,8 +17,15 @@ def __init__(self, owner: str, balance: float): self.balance = balance def decrease_balance(self, amount: float): - pass # писать код тут + balance = self.balance - amount + if balance < self.min_balance: + raise ValueError( + f"the balance must be more than -100, you tried set {balance}" + ) + self.balance = balance -if __name__ == '__main__': - pass # писать код тут +if __name__ == "__main__": + bc1 = BankAccount("denis", 1000.99) + bc1.decrease_balance(399.49) + bc1.decrease_balance(999.99) From a77a9d83f35cb40dd66ff53314441291aa0cec8f Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Sat, 12 Oct 2024 10:32:52 +0300 Subject: [PATCH 12/15] level_7\c_photo_limit.py --- level_7/c_photo_limit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/level_7/c_photo_limit.py b/level_7/c_photo_limit.py index 60ee17e..bd232e0 100644 --- a/level_7/c_photo_limit.py +++ b/level_7/c_photo_limit.py @@ -22,8 +22,8 @@ def validate_photos(self): def generate_photos_limit_message(): - return # код писать тут + return f"Вы можете загрузить не более {PhotoForm.max_photos_number} фотографий" -if __name__ == '__main__': - pass # код писать тут +if __name__ == "__main__": + print(generate_photos_limit_message()) From d41014232556062db6e226f0609d8c556a68e3c0 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Sat, 12 Oct 2024 10:35:30 +0300 Subject: [PATCH 13/15] level_7\d_google_logs.py --- level_7/d_google_logs.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/level_7/d_google_logs.py b/level_7/d_google_logs.py index c281d29..94b11d5 100644 --- a/level_7/d_google_logs.py +++ b/level_7/d_google_logs.py @@ -8,6 +8,7 @@ 2. Исправьте класс GoogleLogger таким образом, чтобы максимальный размер данных, был бы 10 байт 3. Запустите текущий код и убедитесь, что валидация перестала проходить. """ + import json @@ -23,17 +24,19 @@ def is_log_size_valid(self): def get_data_size(self): serialized_data = json.dumps(self.data) - return len(serialized_data.encode('utf-8')) + return len(serialized_data.encode("utf-8")) class GoogleLogger(Logger): + max_log_size = 10 + def is_valid(self): return self.is_log_size_valid() and bool(self.message) -if __name__ == '__main__': +if __name__ == "__main__": google_logger_instance = GoogleLogger( - data={'user_id': 1, 'user_email': 'learn_python.gmail.com'}, - message='User registered', + data={"user_id": 1, "user_email": "learn_python.gmail.com"}, + message="User registered", ) print(google_logger_instance.is_valid()) From 3826d522ae591afc5b3da513210154bb66ecc804 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Sat, 12 Oct 2024 10:38:37 +0300 Subject: [PATCH 14/15] level_7\e_user_str_repr.py --- level_7/e_user_str_repr.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/level_7/e_user_str_repr.py b/level_7/e_user_str_repr.py index fd0a634..53c4cb0 100644 --- a/level_7/e_user_str_repr.py +++ b/level_7/e_user_str_repr.py @@ -13,8 +13,14 @@ def __init__(self, user_id: int, email: str, is_admin: bool): self.email = email self.is_admin = is_admin + def __str__(self) -> str: + return f"User id={self.user_id}, email={self.email}" -if __name__ == '__main__': - user_instance = User(user_id=3, email='dev@yandex.ru', is_admin=True) + def __repr__(self) -> str: + return f"User is_admin={self.is_admin}" + + +if __name__ == "__main__": + user_instance = User(user_id=3, email="dev@yandex.ru", is_admin=True) print(user_instance) print(repr(user_instance)) From c2dec5133fca9182aa3f6be5eb2a4fa73d2e9a66 Mon Sep 17 00:00:00 2001 From: denis sergeevich pekshev Date: Sat, 12 Oct 2024 10:44:56 +0300 Subject: [PATCH 15/15] level_7\f_students_group.py --- level_7/f_students_group.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/level_7/f_students_group.py b/level_7/f_students_group.py index b5a0d02..ce8d0b5 100644 --- a/level_7/f_students_group.py +++ b/level_7/f_students_group.py @@ -15,8 +15,11 @@ def __init__(self, group_number: int, grades: list[int]): self.group_number = group_number self.grades = grades + def __add__(self, other): + return sum([sum(self.grades), sum(other.grades)]) -if __name__ == '__main__': + +if __name__ == "__main__": first_group = StudentGroup(group_number=1, grades=[1, 4, 6, 3]) second_group = StudentGroup(group_number=2, grades=[6, 3, 7, 3, 2]) print(first_group + second_group)