Challenge 2

The full text of this chapter, to read or revisit. To practise, do the exercises.

▶ Do the exercises

Exercise 1 — Battle Training - Five Battles Streak

Time to train your Codémon! Make it fight 5 wild Codémon in a row. - Each battle makes your Codémon lose 10 HP - Display HP after each battle

Starter code
hp = 100 # Fight 5 battles

Exercise 2 — Battle Training - Healing with Potions

After 5 battles, your Codémon is at 50 HP! Time to heal it back to 100 HP. - Each potion restores 15 HP - Keep using potions until HP reaches 100 or more - Display HP after each potion

Infinite Loop Alert!

Before hitting run button, make sure your loop has a condition that will eventually be false. Otherwise, your program will get stuck in an infinite loop and you will have to restart the app !

Starter code
hp = 50 potions_used = 0 # Heal until HP reaches 100

Exercise 3 — Battle Training - Training Multiple Codémon

Great! Now you know how to train one Codémon. Let's train your whole team! - Each Codémon in your team needs to complete 3 training battles - Display which Codémon is training and which battle number

Starter code
team = ["Aquachu", "Pyrochu", "Florachu", "Rockachu"] # Each Codémon does 3 battles

Exercise 4 — Battle Training - Smart Training

It's almost the end of the training, some of your Codémon are too tired to keep going. Check each Codémon's health before last exercise. - Skip Codémon with HP < 30 (too tired to train) - If a Codémon has HP = 0, stop training immediately! You must rush to the Codémon Center right now! - Otherwise, let them train

Starter code
team = ["Aquachu", "Pyrochu", "Florachu", "Rockachu"] health_points = [45, 20, 0, 80] # Check health and train safely
Back to the course