← Back to Loops
πŸŽ’

Inventory Lister

4 of 6

Exercise 3: Inventory Lister

You have a list of items in your game inventory. Use a for loop to print each item with its position number.

Given inventory:

inventory = ["sword", "shield", "potion", "bow", "helmet"]

Expected output:

1. sword
2. shield
3. potion
4. bow
5. helmet

You have 5 items.

Starter Code

inventory = ["sword", "shield", "potion", "bow", "helmet"] for i in range(___): print(f"{}. {inventory[___]}") print(f"\nYou have {___} items.")

Hints

Hint 1 β€” How many times to loop?

Loop through all items: range(len(inventory)) gives you indices 0, 1, 2, 3, 4.

Hint 2 β€” Numbering starts at 1, not 0

The display number is i + 1 (since i starts at 0), but the list index is just i.

print(f"{i + 1}. {inventory[i]}")
Hint 3 β€” Total count

Use len(inventory) to get the number of items.

πŸ’»

Try it yourself

Code: Inventory Lister

Loading Python runtime…
Python …
Loading...
Output
Click "Run" to execute your code...
ℹ️ About this Python environment

βœ… Standard library: heapq, collections, itertools, math, random, functools, datetime, bisect

βœ… Functions, classes, recursion, print()

❌ No file system, subprocess, OS access, or network requests

❌ No pip install (all supported modules are pre-loaded)

⏱️ 5 second execution time limit