From 1e6339c5d17d96162f7ab2b4d0eea52753c4ac08 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 5 Nov 2024 20:35:55 +0200 Subject: [PATCH] task done --- app/main.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 8fbf3053..985559a9 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,46 @@ -# write your code here +from typing import List + + +class Animal: + def __init__( + self, + name: str, + appetite: int, + is_hungry: bool = True + ) -> None: + self.name: str = name + self.appetite: int = appetite + self.is_hungry: bool = is_hungry + + def print_name(self) -> None: + print(f"Hello, I'm {self.name}") + + def feed(self) -> int: + if self.is_hungry: + print(f"Eating {self.appetite} food points...") + self.is_hungry = False + return self.appetite + return 0 + + +class Cat(Animal): + def __init__(self, name: str, is_hungry: bool = True) -> None: + super().__init__(name, appetite=3, is_hungry=is_hungry) + + def catch_mouse(self) -> None: + print("The hunt began!") + + +class Dog(Animal): + def __init__(self, name: str, is_hungry: bool = True) -> None: + super().__init__(name, appetite=7, is_hungry=is_hungry) + + def bring_slippers(self) -> None: + print("The slippers delivered!") + + +def feed_animals(animals: List[Animal]) -> int: + total_food: int = 0 + for animal in animals: + total_food += animal.feed() + return total_food