4 of 6
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.
inventory = ["sword", "shield", "potion", "bow", "helmet"] for i in range(___): print(f"{}. {inventory[___]}") print(f"\nYou have {___} items.")
Loop through all items: range(len(inventory)) gives you indices 0, 1, 2, 3, 4.
The display number is i + 1 (since i starts at 0), but the list index is just i.
print(f"{i + 1}. {inventory[i]}")
Use len(inventory) to get the number of items.
β 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