⚑ IT Wisdom Why are sysadmins so calm? Because they've already seen the worst possible outcome and it's currently in production.
Skilled Practitioner
4249 XP 1751 to Expert
Objective: Use string.Template to fill a switchport config block from a list of port records.
Instructions

Create a file called lab3.py. Use string.Template to generate a config block for each port in the list below.

from string import Template

port_template = Template(
    "interface $interface\n"
    " description $description\n"
    " switchport access vlan $vlan\n"
    " switchport mode access"
)

ports = [
    {"interface": "GigabitEthernet0/1", "description": "PC-Finance-01",  "vlan": 10},
    {"interface": "GigabitEthernet0/2", "description": "PC-Helpdesk-01", "vlan": 20},
    {"interface": "GigabitEthernet0/3", "description": "IP-Phone-01",    "vlan": 30},
]

Print each config block separated by a blank line.

Your output must match exactly:

interface GigabitEthernet0/1
 description PC-Finance-01
 switchport access vlan 10
 switchport mode access

interface GigabitEthernet0/2
 description PC-Helpdesk-01
 switchport access vlan 20
 switchport mode access

interface GigabitEthernet0/3
 description IP-Phone-01
 switchport access vlan 30
 switchport mode access

Run it with python3 lab3.py. Paste your output below and submit.

πŸ’‘ Show Hint
Use port_template.substitute(**port) to unpack the dict as keyword arguments. Use print() after each block and an extra print() to produce the blank line separator β€” or join with "\n\n".join(...).
Paste Your Output
Next Lab β†’