Write a function greet(name, greeting='Hi', cap=None) that returns a greeting string. It should combine the greeting and the name separated by a space (e.g., greet('Alice') → 'Hi Alice'). If cap is provided (an integer), truncate the final string to at most cap characters. If cap is None, return the full string. Use default arguments correctly and avoid mutable default pitfalls.
Practice Parameters & Defaults
Use positional and keyword arguments and default parameter values safely.
Parameters & Defaultswarming python…
Greeting with optional truncation (variant 2)
Press Run to see output, or Check to grade against the tests.
Want a whole course built around parameters & defaults?
Start my path — freeAdaptive practice, streaks, projects with real code review. Free tier gates AI help, never content.