Skip to main content
PRACTICE / PROGRAMMING / PYTHON 06

Functions & Reusable Code Clinic.

Six real Python challenges to create small helpers, pass different inputs, return usable values, handle defaults and compose an IT inventory report.

6 coding challengesReal PythonLine-by-line tracingOptional hints

How to use this clinic: Read each requirement and fix the starter function. Call it with multiple inputs, inspect the variable trace and compare the output. Click Check to grade the expected result. All inventories are fictional.

Review Functions & Reusable Code →
JOELEARNS / PYTHON WORKBENCH

Write it. Run it. Understand it.

Define reusable helpers, pass different arguments, and return results your caller can use. Verify each case in real Python.

Python 3.14 · in-browser
CHALLENGE 01 / 6 · BEGINNER

Return a reusable hostname label

The fictional Northstar inventory needs consistent uppercase hostname labels. Fix label_host() so it returns an uppercase trimmed hostname rather than printing it. Store both call results in first and second; print them on separate lines as 'SW-01' and 'AP-02'. The function must work on two different inputs.

EXPECTED OUTPUTSW-01 AP-02
script.py editableCtrl / Cmd + Enter to run
Your code is stored only in session storage when enabled. Never paste secrets. Clearing this option clears saved drafts, not the editor.
Code executes only when you choose Run or Check. No account needed.
HINTS · OPTIONAL

Try solving it before asking for help. Hints never show a completed program.

PYTHON OUTPUTReady

Your printed output and errors will appear here.

VARIABLE TRACER

Run the code, then step through the executed lines to watch variable values change.

About this environment: The Python runtime is loaded on demand from a version-pinned CDN and runs inside a sandboxed, opaque-origin browser frame. Runs have a time limit. OS/network automation is outside this introductory workbench. If your code calls input(), a response panel appears to supply text to those calls. Don't paste secrets or untrusted scripts.