Practice

Append a Visitor to the Log

MEDIUMFile Handling8 marks
File I/O questionvisitors.txt is pre-loaded for you during grading.

The file visitors.txt already has some names, one per line. Read one new name, append it to the file, then read the whole file back and output every name.

Input: One name. Output: All names in the file after appending, one per line.

Example:

Input:  Chen
Output: Ali
        Ben
        Chen

Sample Test Cases

Test 1: Append a third name
visitors.txt
Ali
Ben
Inputs: Chen
Expected: Ali Ben Chen
Test 2: Append to a single existing name
visitors.txt
Maya
Inputs: Zara
Expected: Maya Zara

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