Editor

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 lesson

Write 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: NYC
# Define your function here
# Test it
build_profile('Alice', age=25, city='NYC')

What Check runs

Your code runs first, then each of these lines. The output must match exactly.

RunsExpected 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

All Python exercises · 50 practice problems · Functions quiz