Player With Health Limits

Python for AIMedium+10 XP+10

Player With Health Limits

Build a game Player.

Part 1: Player(name)

  • A new player has name, health of 100 and score of 0.
  • take_damage(amount) lowers health, but health never goes below 0.
  • heal(amount) raises health, but health never goes above 100.
  • score_point() adds 1 to score.
  • __repr__ returns Player(<name>, health=<health>, score=<score>).

Part 2: play(name, events)

Make a player called name. events is a list of strings, applied in order:

eventmeaning
"hit 30"take 30 damage
"heal 10"heal 10
"point"score a point

Return str() of the player at the end.

Examples

str(Player('Kai'))
returns 'Player(Kai, health=100, score=0)'
name = 'Kai'
events = ['hit 40', 'heal 15', 'point']
returns 'Player(Kai, health=75, score=1)'
name = "Ada"
events = ["hit 30", "point"]
returns 'Player(Ada, health=70, score=1)'
str(Player("Bo"))
returns 'Player(Bo, health=100, score=0)'

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run