Instance vs class attributes — and the bug AI ships every time — step 6 of 9
Claude wrote a Player class with an inventory = [] at the class
level. Two players share the same inventory list. The output is
['sword', 'shield'] ['sword', 'shield'] instead of
['sword'] ['shield'].
Move the list into __init__ so each player gets its own. After the
fix the output should be:
['sword'] ['shield']
The break is on line 2 — but read the whole snippet first.
⌘↵ runs the editor.read, then continue.
Claude wrote a Player class with an inventory = [] at the class
level. Two players share the same inventory list. The output is
['sword', 'shield'] ['sword', 'shield'] instead of
['sword'] ['shield'].
Move the list into __init__ so each player gets its own. After the
fix the output should be:
['sword'] ['shield']
The break is on line 2 — but read the whole snippet first.
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.