The Daily Takings Report

Python for AIHard+10 XP+10

The Daily Takings Report

The café's order log is a CSV file with this header:

1date,item,price,paid,refunded

paid and refunded hold the text yes or no. Prices are text like 3.20.

Task: write daily_report(path) that reads the file and returns a dictionary mapping each date to a list [orders, takings]:

  • An order counts only if it was paid (paid is yes) and not refunded (refunded is no).
  • orders is how many orders counted that day.
  • takings is the total price of the counted orders, rounded to 2 decimal places.
  • A date that appears in the file but has no counted orders still appears, as [0, 0.0].
  • A file with only the header gives {}.

The starter code has a helper, write_orders(path, text), that writes a test file and returns its name.

Examples

path = write_orders('demo.csv', 'date,item,price,paid,refunded\n2026-03-02,latte,3.20,yes,no\n2026-03-02,tea,2.10,yes,yes\n2026-03-03,cake,3.90,no,no\n')
returns {'2026-03-02': [1, 3.2], '2026-03-03': [0, 0.0]}
path = write_orders("cafe1.csv", "date,item,price,paid,refunded\n2026-03-02,latte,3.20,yes,no\n2026-03-02,tea,2.10,yes,yes\n2026-03-03,cake,3.90,no,no\n")
returns {'2026-03-02': [1, 3.2], '2026-03-03': [0, 0.0]}
path = write_orders("cafe2.csv", "date,item,price,paid,refunded\n")
returns {}

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