Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion animal_class.py
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# Пиши свій код тут
class Animal:
def __init__(self, name: str, current_fead: int, max_fead: int, speed: int, loss_fead_per_km: int, position: int = 0) -> None:
self.name = name
self.current_fead = current_fead
self.max_fead = max_fead
self.speed = speed
self.loss_fead_per_km = loss_fead_per_km
self.position = position

def __str__(self):
return f"{self.name} Feed: {self.current_fead}/{self.max_fead} Speed: {self.speed} Loss: {self.loss_fead_per_km} | Position: {self.position}"

def can_move_to(self, distance: int, animal) -> bool:
return animal.current_fead / animal.loss_fead_per_km >= abs(distance - animal.position)

def move_to(self, distance: int) -> None:
if(self.can_move_to(distance, self)):
self.position += distance
self.current_fead -= self.loss_fead_per_km * distance
else:
print("Not enough feed")

def feed(self, calories: int) -> None:
if (self.max_fead >= self.current_fead + calories):
self.current_fead += calories
else:
print("Too much feed")