Challenge 1
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercisesExercise 1 — Trading Post - New Arrivals
You just opened your Trading Post! Trainers are bringing their Codémon to sell. Three trainers arrive: - First trainer brings "Aquachu" - Second trainer brings "Rockachu" - Third trainer brings "Florachu" Add Codémon one by one to your inventory and then print it.
inventory = ["Pyrochu"]
# Code hereExercise 2 — Trading Post - Making Sales
Business is good! Customers are buying your Codémon. Three customers arrive: - First customer buys "Aquachu" - remove it from inventory - Second customer is a gambler! He wants the last Codémon in your list - Third customer buys "Rockachu" - remove it from inventory Display your inventory at the end.
inventory = ["Pyrochu", "Aquachu", "Rockachu", "Florachu"]
# Code hereExercise 3 — Trading Post - Big Delivery
Your inventory is running low! A truck arrives with a big delivery.
The delivery contains: ["Zap", "Aquachu", "Florachu", "Pyrochu"]
- Add all the Codémon from the delivery at once to your inventory.
- It's the end of your day! Count how many Codémon you have in total and store it in total.
inventory = ["Rockachu"]
delivery = ["Zap", "Aquachu", "Florachu", "Pyrochu"]
# Code hereExercise 4 — Trading Post - Customer Request
A customer walks in looking for a specific Codémon!
"Hello! I'm looking for a Zap. Do you have one?"
- Check if you have "Zap" in your inventory.
- If you have it, remove it from your inventory (he buys it).
- If you don't have it, he says: "No problem! I'll take the Codémon you've had for the longest time. I want to make it happy again!"
- Remove the first Codémon from your inventory and store it in oldest_codemon.
inventory = ["Rockachu", "Zap", "Aquachu", "Florachu", "Pyrochu"]
# Code hereExercise 5 — Trading Post - Jeff Bezochu's Offer
A fancy businessman walks into your Trading Post! "Hello! I'm Jeff Bezochu, owner of Amazorb. I want to buy ALL your Codémon stock. Name your price!" -This is a once-in-a-lifetime opportunity! Remove all Codémon from your inventory at once. - Display your inventory after the sale to confirm it's empty.
inventory = ["Rockachu", "Aquachu", "Florachu", "Pyrochu"]
# Code here