Build a Profile String
Intermediate · Write the code · from Python *args, **kwargs, Default Values, and Keyword Arguments
From the lesson: Python *args, **kwargs, Default Values, and Keyword Arguments
Think about ordering coffee. You always need to pick a size - that's required. But extras like oat milk, an extra shot, or caramel drizzle? Those are optional. You only mention them when you want them.
Read the lessonWrite a function called build_profile that takes a required name parameter and uses **kwargs to accept any additional info. It should print the name on the first line, then each key-value pair on subsequent lines in the format key: value (two leading spaces). Print keys in the order they are passed.
Example: build_profile('Alice', age=25, city='NYC') should print:
Alice
age: 25
city: NYCWhat Check runs
Your code runs first, then each of these lines. The output must match exactly.
| Runs | Expected output |
|---|---|
| build_profile('Alice', age=25, city='NYC') | Alice age: 25 city: NYC |
| build_profile('Bob', role='dev') | Bob role: dev |
| build_profile('Eve') | Eve |
More Function Arguments exercises
- Predict the Keyword CallBeginner
- Greeting with a DefaultBeginner
- Sum All NumbersIntermediate
- Fix the Mutable DefaultIntermediate
- Flexible CalculatorAdvanced
- Refactor to Use **kwargsAdvanced
All Python exercises · 50 practice problems · Functions quiz