Problem 120189 · easy · Level 01 Prerequisites & Setup

Receipt Line Item

functions · f-strings · arithmetic · string formatting

Write receipt_line(item, qty, unit_price) that returns one line of a receipt in exactly this form:

<item> x<qty> @ $<unit_price> = $<line total>

The line total is qty * unit_price, computed from the unit price as given (not from its rounded form). Both prices must be shown with two decimal places.

Examples

Input:  item = "Apples", qty = 3, unit_price = 0.5
Output: "Apples x3 @ $0.50 = $1.50"
Input:  item = "Petrol", qty = 4, unit_price = 1.237
Output: "Petrol x4 @ $1.24 = $4.95"
Explanation: 4 * 1.237 = 4.948, shown as 4.95; multiplying the shown price 1.24 by 4 would give 4.96.

Constraints

  • 0 <= qty <= 10**4, 0 <= unit_price <= 10**4; item is non-empty.

Goals

  • Combine text, integers and formatted floats in one f-string
  • Show prices with two decimals
Starting Python…