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)) # 2Worked example (different data from your task)
bag = ["pen", "book"]
bag.append("phone")
print(bag) # ['pen', 'book', 'phone']
print(len(bag)) # 3Common mistake: append changes the list and returns None, so bag = bag.append("x") throws your list away. Call it on its own line.
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.
Hint
loot.append("potion") then print(len(loot))Output appears here.