183. Python Program to Track a Game Character's Health
Medium__init__
Overview
Change an object's attribute again and again, starting from a default value.
Problem Statement
Define a class Character whose __init__ takes a name and a health that is 100 by default. Read the character's name and create it with only the name. Then read the number of hits, and for each hit read the damage (a whole number). After each hit, lower the character's health by the damage (it never goes below 0), and print a line like Rocky took 30 damage, health 70.
After all the hits, print Rocky is still standing if the health is above 0, or Rocky is out if it is 0.
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
The name, then the number of hits, then one damage per line. Example:
Rocky
3
30
25
10
Output
The output for that example:
Rocky took 30 damage, health 70
Rocky took 25 damage, health 45
Rocky took 10 damage, health 35
Rocky is still standing
The tests try 4 different inputs, including a character that takes no hits.