Python · Dictionaries
Challenge 1
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercises
Exercise 1 — Battle Records Start
Track your Codémon battle wins! Create a record system. - Create a dictionary with battle records: Aquachu has 15 wins, Pyrochu has 22 wins, Florachu has 8 wins, Zap has 18 wins - Display the complete battle records
Starter code
# Code here
Exercise 2 — Retiring a Codémon
Florachu is retiring from battles! Remove it from records. - Remove Florachu from the dictionary and store its wins - Display how many wins Florachu had - Display the updated battle records
Starter code
battle_records = {"Aquachu": 15, "Pyrochu": 22, "Florachu": 8, "Zap": 18} print(f"Battle records: {battle_records}")
Exercise 3 — New Recruit and Average
Rockachu joins your team! Track its stats and calculate the average. - Add Rockachu to battle records with 5 wins - Calculate the average wins across all Codémon - Display the average
Starter code
battle_records = {"Aquachu": 15, "Pyrochu": 22, "Zap": 18}
Exercise 4 — Finding the Champion
Time to find which Codémon is the battle champion! - Loop through all Codémon and their wins - Find which one has the most wins - Display the champion name and its win count
Starter code
battle_records = {"Aquachu": 15, "Pyrochu": 22, "Zap": 18, "Rockachu": 5}
Back to the course