← Back to Basics

Backpack Manager

4 of 8

Exercise 5: Backpack Manager πŸŽ’

πŸ“‹ Lists πŸ”‚ For Loops

Your Task

Start with: inventory = ["sword", "potion", "shield"]

Do this in order:

  1. Print the inventory
  2. Add "helmet" to the end
  3. Add "gem" to the beginning
  4. Remove "potion"
  5. Print the inventory
  6. Print: How many items? What's the first item? What's the last item?
  7. Use a for loop to print each item numbered (1. gem, 2. sword, etc.)

Example Output

['sword', 'potion', 'shield']
['gem', 'sword', 'shield', 'helmet']
4 items
First: gem
Last: helmet
1. gem
2. sword
3. shield
4. helmet

Try it yourself

Code: Backpack Manager

Loading Python runtime…
Python …
Loading...
bash
$ Click "Run" to execute your code...