Old-Style % String Formatting

Medium ⏱ 12 min 60% acceptance ★★★★★ 4.9
Write format_percent_style(name, score) that builds the string "<name> scored <score>%" using the legacy % formatting operator ("%s ... %d%%" % (...)), not an f-string or .format(). This operator still shows up in older codebases and logging templates.

Examples

Example 1
Input
name = 'Aman', score = 87
Output
'Aman scored 87%'
Explanation

%s substitutes the name, %d substitutes the integer score, and %% escapes to a literal percent sign.

Constraints

  • score is an integer between 0 and 100.

Topics

StringsString Formatting

Companies

TCSInfosysCapgemini

Hints

Hint 1

`"%s scored %d%%" % (name, score)` — the doubled `%%` produces one literal `%`.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.