PIXELBANKv8.2.1
Menu

Function with Default Args

Problem Statement

Create functions with default arguments and keyword arguments.

Background

Python functions support:

  • Default arguments: def f(a, b=10)
  • Keyword arguments: f(a=1, b=2)
  • *args: Variable positional arguments
  • **kwargs: Variable keyword arguments

Your Task

Write a function **create_profile(name, age=18, city="Unknown", extra) that creates a user profile.

Output Format

Return a dictionary with all provided information:

  • "name": The name
  • "age": The age (default 18)
  • "city": The city (default "Unknown")
  • Plus any extra keyword arguments

Example:

Input:
create_profile("Alice", age=25, city="NYC", job="Engineer")
Output:
{'name': 'Alice', 'age': 25, 'city': 'NYC', 'job': 'Engineer'}
Reasoning:

Named args override defaults, **kwargs captures extra args

Constraints:

  • name is required
  • age defaults to 18
  • city defaults to "Unknown"
  • Include any extra keyword arguments
Editor

Test Results

0/0
Run code to see test results.