Třídy – Řešení [0]
class Cat:
def __init__(self): # Init funkce nemusi brat jako parametr
self.number_of_lives = 9 # pocet zivotu, ten je pokazde 9.
def meow(self):
print("Moew, moew, meooooow!")
def is_alive(self):
return self.number_of_lives > 0
def lose_life(self):
if not self.is_alive():
print("Cannot kill dead cat!")
else:
self.number_of_lives -= 1
def eat(self, food):
if not self.is_alive():
print("It is pointless to feed dead cat!")
if food == "fish" and self.number_of_lives < 9:
self.number_of_lives += 1
print("Cat ate fish and gained one life.")
else:
print("Cat is eating.")