Lab 2 of 5
Β·
Semi-Guided
Loop Through Devices and Skip Offline Ones
Objective: Use a for loop with continue to process only online devices.
Instructions
Create a file called lab2.py. Write a script using the device list below. Loop through every device. If a device is offline (online: False), skip it using continue. For every online device, print Processing: <name>.
devices = [
{"name": "sw-core-01", "online": True},
{"name": "sw-access-01", "online": False},
{"name": "rtr-edge-01", "online": True},
{"name": "sw-access-02", "online": False},
]
Run it with python3 lab2.py. Paste your output below and submit.
Starter Code
devices = [
{"name": "sw-core-01", "online": True},
{"name": "sw-access-01", "online": False},
{"name": "rtr-edge-01", "online": True},
{"name": "sw-access-02", "online": False},
]
for device in devices:
if not device["online"]:
continue
print(f"Processing: {device['name']}")
π‘ Show Hint
Use "if not device["online"]: continue" to skip offline devices. The continue statement jumps straight to the next iteration without running the print line.
Paste Your Output