Pounds and Pence

Data with PythonMedium+10 XP+10

Pounds and Pence

A café's price list was typed by three different people. Every price is text, written in one of two ways:

  • in pounds, with a £ sign, like "£2.50", "£1,250.00" (with a comma for thousands) or " £3.00 " (with stray spaces)
  • in pence, ending in p, like "85p" or " 99p", where "85p" means £0.85

Write menu_total(prices). Clean the text, turn every price into a number of pounds, and return the total in pounds, rounded to 2 decimal places.

prices always has at least one price, and every price is in one of the two forms above.

Examples

prices = ["£2.50", " £3.00 ", "85p"]
returns 6.35
prices = ["£1,250.00", "99p", " 5p", "£0.45"]
returns 1251.49

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