174. Python Program to Read a File Line by Line
EasyRead
Overview
A for loop reads a file one line at a time. strip() cleans each line.
Problem Statement
Read a whole number n, then n names, one per line. Write the names into a file called names.txt, one per line, and close it. Then open names.txt again and loop over its lines, printing each name with its line number, a dot and a space in front: 1. Sunny.
Your program runs in the browser, so the file lives only in this tab's memory. Create it with "w" before you read it.
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Input
The number of names, then the names. Example:
3
Sunny
Rocky
Lucky
Output
The output for that example:
- Sunny\
- Rocky\
- Lucky
The tests try 3 different inputs.