Find the Gaps

Python for AIMedium+10 XP+10

Find the Gaps

A poem file uses empty lines to separate its verses. How many empty lines are there?

Write count_blank_lines(path). Return how many lines in the file are completely empty.

  • Remember: each line from the loop still has its newline on the end. An empty line in the middle of a file arrives as "\n".
  • A line with a space on it is not empty here. Only a line with nothing before its newline counts.
  • An empty file has 0 blank lines.

Leave the make_file helper as it is.

Examples

path = make_file('poem.txt', 'roses\n\nviolets\n')
returns 1
path = make_file("bl_a.txt", "a\n\nb\n\nc\n")
returns 2
path = make_file("bl_b.txt", "no gaps\nhere\n")
returns 0

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