Append Mode

Lab Python Intermediate 20 points

Write start to log.txt. Then read n events and append each one on its own line using mode "a". Finally print the number of lines in the file and its last line.

Input

Line 1: n. Then n events.

Output

Two lines.

Example

Input

2
login
logout

Output

3
logout
Sample input available Sample output available
Editor
Python

Hints

"a" adds to the end instead of overwriting.

read().splitlines() gives a list of lines without \n.

Solution explanation

Mode "w" truncates, "a" appends, "r" (the default) reads.

Show solution
with open("log.txt", "w") as f:
    f.write("start\n")
for _ in range(int(input())):
    with open("log.txt", "a") as f:
        f.write(input() + "\n")
with open("log.txt") as f:
    lines = f.read().splitlines()
print(len(lines))
print(lines[-1])
Output
Answer
HOME LEARN COMMUNITY DASHBOARD