Till Total From Text

Data with PythonEasy+10 XP+10

Till Total From Text

A market stall's till saved every number as text. A price looks like "2.50" and a quantity looks like "3", but they're all strings, so adding them up would just glue them together.

Every value is a clean number written as text. Nothing is blank or mistyped.

Task: write till_total(sales).

  • sales is a list of dictionaries, each with item, price and qty, all as text. Turn it into a DataFrame.
  • Convert price to numbers with decimals and qty to whole numbers.
  • Return the total takings, the sum of price × qty over every row, rounded to 2 decimal places.

There is always at least one sale.

Examples

sales = [{"item": "jam", "price": "2.50", "qty": "3"}, {"item": "honey", "price": "4.80", "qty": "2"}]
returns 17.1
sales = [{"item": "eggs", "price": "1.90", "qty": "12"}]
returns 22.8

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