Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Create a function with keyword-only parameters

Practice defining keyword-only parameters using '*' and using them for clearer function calls.

Python practice15 minFunctions & ScopeIntermediateLast updated March 17, 2026

Problem statement

Define format_point(x, y, *, label=None, precision=2) which returns a formatted string for the point (x, y). label and precision must be keyword-only parameters. precision controls the number of decimal places (use Python rounding rules with format specification). If label is provided, prepend it followed by ': '. For example, format_point(1.234, 4.567, label='P', precision=1) -> "P: (1.2, 4.6)".

Task

Write a function that enforces keyword-only arguments and uses them to control output formatting.

Examples

Labeled point with precision 1

Input

format_point(1.234, 4.567, label='A', precision=1)

Output

A: (1.2, 4.6)

label is provided and precision=1 rounds coordinates to one decimal place.

Input format

A function call format_point(x, y, *, label=None, precision=2). label and precision must be passed as keywords if used.

Output format

Return a string representing the point, optionally prefixed with the label.

Constraints

Enforce label and precision as keyword-only by using '*' in the function signature. precision is a non-negative integer.

Samples

Sample 1

Input

format_point(1.234, 4.567)

Output

(1.23, 4.57)

Default precision is 2 and no label is provided.