Lab 1: The Resource Alert (Beginner)
Scenario: You need to notify the team about high CPU usage. Task: Use an f-string to combine a server name and a usage percentage.
Python
server = "Prod-Web-01"
cpu_usage = 94.5
# Task: Print "ALERT: Prod-Web-01 is at 94.5% capacity!"
message = f"ALERT: {server} is at {cpu_usage}% capacity!"
print(message)
Lab 2: The Security Audit Table (Intermediate)
Scenario: You are printing a list of open ports. You want the output to be neatly aligned. Task: Use f-string padding to align text. (Hint: :<10 aligns left with 10 spaces).
Python
port_data = [("SSH", 22), ("HTTP", 80), ("HTTPS", 443)]
print(f"{'SERVICE':<10} | {'PORT':<5}")
print("-" * 18)
for service, port in port_data:
print(f"{service:<10} | {port:<5}")
Lab 3: The Cost Calculator (Architect Level)
Scenario: You have a list of microservice costs and you need to print a summary that includes a 10% tax. Task: Perform the math calculation directly inside the f-string.
Python
base_cost = 500.00
tax_rate = 0.10
# Task: Calculate total and format to 2 decimal places
print(f"Base: ${base_cost:.2f}")
print(f"Total (inc. tax): ${base_cost * (1 + tax_rate):.2f}")Lab 1: The Cloud Cost Estimator (Beginner)
Scenario: You have a daily server cost and need to estimate the yearly budget, formatted nicely. Task: Calculate the total and format it with commas and 2 decimal places.
Python
daily_cost = 45.50
days = 365
# Calculation inside the f-string
print(f"Estimated Yearly Budget: ${daily_cost * days:,.2f}")
# Output: Estimated Yearly Budget: $16,607.50
Lab 2: The Log Aligner (Intermediate)
Scenario: You are printing a table of services and their statuses. You want the columns to line up perfectly for readability. Task: Use alignment syntax < (left) and > (right).
Python
services = [("Nginx", "Running"), ("Docker", "Stopped"), ("K8s", "Running")]
print(f"{'SERVICE':<10} | {'STATUS':>10}")
print("-" * 23)
for name, status in services:
print(f"{name:<10} | {status:>10}")
Lab 3: The Dynamic JSON Builder (Architect Level)
Scenario: You need to generate a JSON payload string to send to a security tool API. Task: Insert variables into a string that looks like JSON. Note: Double the curly braces {{ to print literal braces.
Python
user = "dev_admin"
role = "read-write"
# We use {{ to escape the braces so they appear in the final string
json_payload = f'{{"username": "{user}", "permissions": "{role}"}}'
print(f"Sending payload: {json_payload}")
# Output: Sending payload: {"username": "dev_admin", "permissions": "read-write"}