Skip to content
C

Line Counter

Easypython

Write a program that writes a given number of lines to a text file, then reads that file back and counts its total number of lines.

What the problem means: this exercises the full write-then-read cycle — save some text to disk, then open it again and count how many lines it contains.

Approach: read how many lines there are and the lines themselves, write each one (with a newline) to a file using with open(...) as f:, then reopen it and count with readlines().

Input: First line: the number of lines n. Next n lines: the text content itself.

Output: One line: Total lines: <n>

Input (stdin)

Output

Run your code to see output here...