#1
class GameCharacter:
def __init__(self, name, damage, health):
self.name = name
self.damage = damage
self.health = health
def attack(self):
print(f"{self.name} наносит {self.damage} урона")
def take_damage(self, amount):
self.health -= amount
self.health = 0 if self.health < 0 else self.health
print(f"{self.name} получил {amount} урона."
f" Осталось здоровья: {self.health}")
Char1 = GameCharacter('Machachev', 100, 1000)
Char1.attack()
Char1.take_damage(52)
Char1.take_damage(67)
Char1.take_damage(69)
print(Char1.health)
#2
class Cart:
def __init__(self, owner):
self.owner = owner
self.items = {}
def add_item(self, name, price):
self.items[name] = price
def get_total(self):
return sum(self.items.values())
def show_items(self):
for keys, values in self.items.items():
print(f"{keys} - {values}")
if len(self.items) == 0:
print("Корзина пуста")