Topics / 🐍 Python Foundations / 🎒 Level 2: Lists, Dictionaries and Loops

Python exercise · about 5 minutes · free

Lists: Loot Drop

A list is your backpack: ordered, and it always has room for one more potion.

Lists hold many items. append() adds one, len() counts them.

loot = ["sword"]
loot.append("map")
print(len(loot))  # 2

Worked example (different data from your task)

bag = ["pen", "book"]
bag.append("phone")
print(bag)       # ['pen', 'book', 'phone']
print(len(bag))  # 3

Common mistake: append changes the list and returns None, so bag = bag.append("x") throws your list away. Call it on its own line.

loot = ["sword", "shield"]: sword, shield. loot.append("potion"): sword, shield, potion. len(loot) → 3loot = ["sword", "shield"]sword0shield1loot.append("potion")sword0shield1potion2len(loot) → 3
Your quest: Add "potion" to loot, then print how many items you have.
Try it now Runs in your browser. No sign-in needed. Ctrl+Enter to run.
Hintloot.append("potion") then print(len(loot))
Output appears here.

Open it in the full course → Free with Google: saves your progress and unlocks 627 lessons.

In this level you'll learn:
More in Level 2: Lists, Dictionaries and Loops

Share on LinkedIn