# Homework 27, problem 2 -- solution.

class Character:
    def __init__(self, name, hp):
        self.name = name
        self.hp = hp
        self.max_hp = hp

    def take_damage(self, amount):
        self.hp = self.hp - amount
        if self.hp < 0:
            self.hp = 0

    def heal(self, amount):
        self.hp = self.hp + amount
        if self.hp > self.max_hp:
            self.hp = self.max_hp

    def is_alive(self):
        return self.hp > 0

    def report(self):
        print(f"{self.name}: {self.hp} / {self.max_hp} HP (alive: {self.is_alive()})")

c = Character("Keiko", 100)
c.report()
c.take_damage(30)
c.report()
c.take_damage(80)
c.report()
c.heal(20)
c.report()
