Problem 189744 · hard · Phase 01 Prerequisites & Setup

Write the Cheque in Words

strings · functions · lists · integer division · modulo

On a paper cheque the amount is written in words, with the cents as a fraction of 100. Write cheque_words(amount) that turns the text amount into that line.

amount may start with $, may use commas between groups of three digits, and may have a decimal point followed by one or two digits ("12.5" means 12 dollars 50 cents). There may be no decimal point at all.

Format of the answer:

  • the dollars in English words, then and CC/100 dollars where CC is the cents as two digits;
  • zero dollars is zero;
  • groups use million and thousand; a group of zero is left out entirely;
  • inside a group of three digits: <digit> hundred if the hundreds digit is not 0, followed by the rest; 21-99 are joined with a hyphen (forty-two) unless the ones digit is 0 (forty);
  • words are separated by single spaces; no and or commas inside the dollar words;
  • only the first letter of the whole line is a capital.

Examples

Input:  amount = "$1,234.56"
Output: "One thousand two hundred thirty-four and 56/100 dollars"

Input:  amount = "0.07"
Output: "Zero and 07/100 dollars"

Input:  amount = "215017090.1"
Output: "Two hundred fifteen million seventeen thousand ninety and 10/100 dollars"

Constraints

  • 0 <= dollars <= 999,999,999; commas, when present, are placed correctly

Goals

  • Clean an amount written with $, commas and 0-2 decimals
  • Break a number into groups of three digits and name each group
  • Join words with the exact spacing, hyphens and capitalisation required
Starting Python…