Problem 137818 · medium · Phase 01 Prerequisites & Setup

Aligned Receipt

loops · strings · formatting · arithmetic

Print a shop receipt. items is a list of [name, price_cents, quantity]. Each item line shows the name and the line total price_cents * quantity; the last line shows TOTAL and the sum of all line totals. Money is written as dollars and cents with exactly two decimals (e.g. 250 cents is 2.50, 1188 is 11.88).

Layout: every line is name padded on the right with spaces to the width W, then two spaces, then the money string padded on the left to the width M, where W is the length of the longest name including TOTAL, and M is the length of the longest money string including the total. Return the list of lines.

Examples

Input:  items = [["milk", 125, 2], ["bread", 300, 1]]
Output: ["milk   2.50", "bread  3.00", "TOTAL  5.50"]

Input:  items = []
Output: ["TOTAL  0.00"]

Constraints

  • 0 <= len(items) <= 200, 1 <= price_cents <= 10**6, 1 <= quantity <= 1000

Goals

  • Convert cents to a dollars.cents string without floats
  • Compute column widths before formatting any line
  • Append a summary line that follows the same layout
Starting Python…