Practice

Read Names from File

MEDIUMFile Handling
File I/O questionnames.txt is pre-loaded for you during grading.

A file called names.txt has already been created and contains three names, one per line:

Alice
Bob
Charlie

Open the file for reading. Read each name and output it. Close the file when done.

Input: None (read from the file). Output: Three names, each on a separate line, exactly as stored in the file.

Example output:

Alice
Bob
Charlie

Sample Test Cases

Test 1: Three names in file
names.txt
Alice
Bob
Charlie
Expected: Alice Bob Charlie

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started