Fix the dollar total from payment log lines

Review the AI's codeMedium15 min

Your task

Your finance job totals every dollar amount that appears in a day's payment logs. The first version used m.group(), which includes the $ sign, so float("$12.50") crashed on the first real amount. The new version reads only the number.

An assistant wrote sum_amount_cents(log_lines). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • log_lines: the log lines, as strings.
  • Return the total of every amount on every line, in cents, as an integer.

Rules the tests check:

  • An amount is a $, then one or more digits from 0 to 9, then optionally a . followed by exactly two digits.
  • As a regex, an amount is \$([0-9]+)(\.[0-9]{2})?.
  • With the optional part, the two digits are the cents. Without it, the cents are 0. So $12.5 counts as 1200 cents, and $1.234 counts as 123 cents: only the first two digits after the dot belong to the amount.
  • Leading zeros are fine: $007.50 is 750 cents.
  • A $ with no digit right after it is not an amount. In $$7.25, the second $ starts the amount.
  • Amounts never overlap: after an amount, look for the next $ after its last character.
  • The total must be exact for any number of amounts.

Examples

sum_amount_cents(log_lines: list[str]) -> int
Example 1
Inputsum_amount_cents(["paid $12.50 to vendor", "refund $3.00"])
Output1550
Example 2
Inputsum_amount_cents(["no amounts here", "total: 42"])
Output0
Example 3
Inputsum_amount_cents(["$100 and $0.99"])
Output10099