Skip to content

Commit

Permalink
Replaced .format with f-strings and fixed type annotations for bite()…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
Lyutillis committed Oct 14, 2023
1 parent d410032 commit 6c5fdfc
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ def __init__(self,
Animal.alive.append(self)

def __repr__(self) -> str:
name = f"Name: {self.name}, "
health = f"Health: {self.health}, "
hidden = f"Hidden: {self.hidden}"
return "{" + name + health + hidden + "}"
return f"{{Name: {self.name}, " \
f"Health: {self.health}, " \
f"Hidden: {self.hidden}}}"


class Herbivore(Animal):
Expand All @@ -24,9 +23,8 @@ def hide(self) -> None:

class Carnivore(Animal):
@staticmethod
def bite(herbivore: Herbivore) -> None:
if herbivore.hidden or isinstance(herbivore, Carnivore):
return
herbivore.health -= 50
if herbivore.health <= 0:
Animal.alive.pop(Animal.alive.index(herbivore))
def bite(herbivore: Animal) -> None:
if not (herbivore.hidden or isinstance(herbivore, Carnivore)):
herbivore.health -= 50
if herbivore.health <= 0:
Animal.alive.remove(herbivore)

0 comments on commit 6c5fdfc

Please sign in to comment.