Lab 2 of 5
Β·
Semi-Guided
Print a Formatted Device Inventory
Objective: Loop through a list of device dictionaries and print a formatted summary.
Instructions
Create a file called lab2.py. Using the inventory below, loop through every device and print one line per device in the format: name | ip | site.
inventory = [
{"name": "sw-core-01", "ip": "10.1.1.1", "type": "switch", "site": "HQ"},
{"name": "sw-access-01","ip": "10.1.1.2", "type": "switch", "site": "HQ"},
{"name": "rtr-edge-01", "ip": "10.1.1.254", "type": "router", "site": "HQ"},
]
Run it with python3 lab2.py. Paste your output below and submit.
Starter Code
inventory = [
{"name": "sw-core-01", "ip": "10.1.1.1", "type": "switch", "site": "HQ"},
{"name": "sw-access-01","ip": "10.1.1.2", "type": "switch", "site": "HQ"},
{"name": "rtr-edge-01", "ip": "10.1.1.254", "type": "router", "site": "HQ"},
]
for device in inventory:
print(f"{device['name']} | {device['ip']} | {device['site']}")
π‘ Show Hint
Use an f-string: print(f"{device['name']} | {device['ip']} | {device['site']}")
Paste Your Output