Prices That Won't Add Up

Data with PythonMedium+10 XP+10

Prices That Won't Add Up

A market stall's prices were typed into a spreadsheet by hand, so the column is all text. Most entries are proper numbers like "2.50" or "3", but some aren't: "free", "n/a", an empty "", or "2,50" typed with a comma.

Write price_check(prices), where prices is a list of strings. Convert them to numbers, treating anything that can't be read as a number as missing.

Return a list of two values:

  1. the total of the prices that could be read, rounded to 2 decimal places (0.0 if none could be read)
  2. how many prices could not be read, as a whole number

If prices is empty, return [0.0, 0].

Examples

prices = ["2.50", "3.00", "free", "2.80"]
returns [8.3, 1]
prices = ["1.20", "", "n/a", "4", "2,50"]
returns [5.2, 3]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run