Lines Versus Records

Python for AIMedium+10 XP+10

Lines Versus Records

A help-desk system exports tickets as CSV. Some ticket notes run over several lines, so the number of lines in the file and the number of real rows don't match. The team wants to see both numbers side by side.

Task: write lines_and_rows(path, text). It returns a list of two whole numbers:

  1. how many lines the file has, counted by looping the open file line by line,
  2. how many rows csv.reader finds in it.

Count the line of column names in both numbers. Every file ends with "\n".

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. import csv is already at the top of the starter code.

Examples

path = 'tickets.csv'
text = 'id,note\n1,"printer jammed\nagain"\n2,fine\n'
returns [4, 3]
path = 'tickets2.csv'
text = 'id,note\n1,ok\n2,fine\n'
returns [3, 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