Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 8

Write a function that handles keyword arguments

Easy

8 minute session

Summary

Use **kwargs to accept arbitrary keyword arguments and process them.

Problem statement

Implement count_kwargs(**kwargs) which accepts any number of keyword arguments and returns an integer count of those keyword arguments. The function should work when called with zero or many keyword arguments.

Task

Create a function count_kwargs(**kwargs) that returns how many keyword arguments were passed.

Examples

Count two keyword args

Input

count_kwargs(name='Alice', active=True)

Output

2

Explanation

Two keyword arguments (name and active) were provided.

Input format

Zero or more keyword arguments in the form key=value.

Output format

An integer representing the number of keyword arguments passed.

Constraints

Do not use external libraries. The order of kwargs is not important; only the count matters.

Samples

Sample input 0

count_kwargs()

Sample output 0

0

Explanation 0

No keyword arguments, so the count is 0.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

09:07 PM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.