Build an Invoice Line with f-strings

Medium ⏱ 12 min 58% acceptance ★★★★★ 4.7
Write format_invoice_line(item, qty, price) that returns a single formatted line using an f-string: the item name left-aligned in a 10-character field, the quantity right-aligned in a 5-character field, and the price right-aligned in a 10-character field with exactly 2 decimal places.

Examples

Example 1
Input
item = 'Mouse', qty = 2, price = 799.5
Output
'Mouse         2    799.50'
Explanation

'Mouse' padded to 10 chars, '2' right-aligned in 5 chars, '799.50' right-aligned in 10 chars.

Constraints

  • len(item) <= 10
  • 0 <= qty < 10^4
  • price >= 0

Topics

StringsString Formatting

Companies

RazorpayPayPalWalmart

Hints

Hint 1

f-string alignment syntax: `{value:<width}` for left, `{value:>width}` for right.

Hint 2

Add `.2f` after the width for fixed decimal places: `{price:>10.2f}`.

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