← Back to Basics

Battle Time

7 of 8

Exercise 8: Battle Time ⚔️

📦 Functions

Your Task

Part A: Make a function show_health(name, hp) that prints "[name] has [hp] HP". Call it 3 times.

Part B: Make a function calc_damage(base, multiplier) that returns base × multiplier. Call it and print the result.

Part C:

player_hp = 100 damage = calc_damage(15, 2) # Calculate damage player_hp = player_hp - damage # Subtract it show_health("Hero", player_hp) # Show new health

Example Output

=== Part A ===
Steve has 100 HP
Alex has 75 HP
Creeper has 20 HP

=== Part B ===
Damage: 30

=== Part C ===
Hero has 70 HP

Try it yourself

Code: Battle Time

Loading Python runtime…
Python
Loading...
bash
$ Click "Run" to execute your code...