Lab 3 of 5
Β·
Semi-Guided
Write a Function That Formats Hostnames
Objective: Define and call a function that strips whitespace and lowercases a hostname.
Instructions
Create a file called lab3.py. Write a function called format_hostname(name) that:
- Strips leading and trailing whitespace
- Converts the name to lowercase
- Includes a one-line docstring as the first line inside the function body
Test it against these three hostnames:
hostnames = [" SW-CORE-01 ", "RTR-EDGE-01", " FW-DMZ-01"]
Your output must match exactly:
sw-core-01
rtr-edge-01
fw-dmz-01
Run it with python3 lab3.py. Paste your output below and submit.
π‘ Show Hint
def format_hostname(name): with a docstring on the next line inside the function. Use name.strip().lower() to clean the string. Loop through the list and call format_hostname() on each.
Paste Your Output