From b506989a30674f0cd32e36b2a43a1f82e7152430 Mon Sep 17 00:00:00 2001 From: Yurii Popov Date: Mon, 28 Oct 2024 11:25:26 +0200 Subject: [PATCH 1/3] add lab 5 home kind and pet classes --- src/.DS_Store | Bin 0 -> 6148 bytes src/main.py | 14 ++++++++++++++ src/models/home.py | 27 +++++++++++++++++++++++++++ src/models/kind.py | 7 +++++++ src/models/pet.py | 30 ++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 src/.DS_Store create mode 100644 src/main.py create mode 100644 src/models/home.py create mode 100644 src/models/kind.py create mode 100644 src/models/pet.py diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 None: + self.pets.append(pet) + + + def __str__(self) -> str: + return "\n".join([str(pet) for pet in self.pets]) + + + + def sort_by_age(self) -> None: + for n in range(len(self.pets) - 1, 0, -1): + for i in range(n): + if self.pets[i].age > self.pets[i + 1].age: + self.pets[i].age, self.pets[i + 1].age = self.pets[i + 1].age, self.pets[i].age diff --git a/src/models/kind.py b/src/models/kind.py new file mode 100644 index 0000000..b9aa1fd --- /dev/null +++ b/src/models/kind.py @@ -0,0 +1,7 @@ +from enum import Enum + +class Kind(Enum): + DOG = "DOG" + CAT = "CAT" + BIRD = "BIRD" + FISH = "FISH" \ No newline at end of file diff --git a/src/models/pet.py b/src/models/pet.py new file mode 100644 index 0000000..f13bb77 --- /dev/null +++ b/src/models/pet.py @@ -0,0 +1,30 @@ +from models.kind import Kind + + +class Pet: + def __init__(self, name: str, kind: Kind, breed: str, age: int, greeting: str, mass: float): + self.name:str = name + self.breed: str = breed + self.kind: Kind = kind + self.age:int = age + self.greeting: str = greeting + self.mass:float = mass + + + def are_friends(self, *other_pets) -> list: + friends: list[Pet] = [] + for pet in other_pets: + if type(pet) is Pet and abs(self.age - pet.age) <= 2: + friends.append(pet) + else: + continue + + return friends + + + def is_polite(self) -> bool: + return "hello" in self.greeting.lower() + + + def __str__(self): + return f"{self.name} is a {self.kind} ({self.breed}) and is {self.age} years old. {self.greeting}" From 00182e76c23097a1ccf2db2088720299f856f543 Mon Sep 17 00:00:00 2001 From: Yurii Popov Date: Mon, 4 Nov 2024 14:01:32 +0200 Subject: [PATCH 2/3] fix code review problem change cycle of friendship print --- .idea/.gitignore | 8 ++++++++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ .idea/python_labs.iml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ src/main.py | 5 ++++- 7 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/python_labs.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..73198b6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..af59ef0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/python_labs.iml b/.idea/python_labs.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/python_labs.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main.py b/src/main.py index 4114ea4..0a316b3 100644 --- a/src/main.py +++ b/src/main.py @@ -7,7 +7,10 @@ def main(): home.sort_by_age() print(f"\n{home}\n") print(f"\n{home.pets[0].is_polite()}\n") - print(f"\n{[str(pet) for pet in home.pets[0].are_friends(home.pets[1], home.pets[2], home.pets[3])]}\n") + tuple_of_pets_for_friendship: tuple = (home.pets[1], home.pets[2], home.pets[3]) + friends = home.pets[0].are_friends(*tuple_of_pets_for_friendship) + for pet in friends: + print(f"this is friend {pet.name}") if __name__ == "__main__": From 20c49de0e8d8ee2d62606337cc5ad9affbc95e85 Mon Sep 17 00:00:00 2001 From: Yurii Popov Date: Mon, 4 Nov 2024 14:12:08 +0200 Subject: [PATCH 3/3] remove another files --- .idea/.gitignore | 8 -------- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/misc.xml | 7 ------- .idea/modules.xml | 8 -------- .idea/python_labs.iml | 8 -------- .idea/vcs.xml | 6 ------ src/.DS_Store | Bin 6148 -> 0 bytes 7 files changed, 43 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/python_labs.iml delete mode 100644 .idea/vcs.xml delete mode 100644 src/.DS_Store diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2d..0000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 73198b6..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index af59ef0..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/python_labs.iml b/.idea/python_labs.iml deleted file mode 100644 index d0876a7..0000000 --- a/.idea/python_labs.iml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0