runtime
171 / 500
question 171 Exceptions & Validation · easy

Read a money amount from a spreadsheet

A finance spreadsheet exports amounts as text such as "$1,234.50". Before totals can be added up, each one must become a number, and the ones that can't be read must be marked rather than guessed.

Functionparse_money(text)
Cleaningremove spaces at the ends, then one leading $ if present, then every comma
Returnsthe amount as a float, or None when the cleaned text isn't a number
Examples
callparse_money('$1,234.50')returns1234.5
callparse_money('12.93')returns12.93
callparse_money('N/A')returnsNone

Loading your progress…

Read a money amount from a spreadsheet — Python practice · Runtime