Steps per Weekday

Python for AIMedium+10 XP+10

Steps per Weekday

A walking club logs everyone's daily steps. Each column is a day and each row is one member's week.

Task: write column_totals(path, text). It returns a list of totals, one per column, in column order. Each total is the sum of that column's values over every data row.

The starter code includes a small helper, write_text, and already calls it for you: it saves text into a file named path. Your code then opens that file and reads it.

  • The first line holds the day names. Leave it out of the totals.
  • Every other value is a whole number. Return the totals as ints.
  • Every line ends with "\n" and has the same number of values. There are no blank lines.
  • If there are no data rows, every total is 0, so return one 0 per column.

Examples

path = 'walk.csv'
text = 'mon,tue,wed\n100,250,0\n300,50,20\n'
returns [400, 300, 20]
path = 'walk2.csv'
text = 'sat,sun\n5000,7000\n'
returns [5000, 7000]

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