Write then Read

Lab Python Intermediate 20 points

Read n lines of text and write them to notes.txt. Then open the file again, read it back and print each line numbered as N: text.

Input

Line 1: n. Then n lines.

Output

n numbered lines.

Example

Input

3
buy milk
call mum
learn python

Output

1: buy milk
2: call mum
3: learn python
Sample input available Sample output available
Editor
Python

Hints

open(name, "w") creates or overwrites a file.

Iterating over a file gives its lines, each ending with \n.

Solution explanation

The with statement closes the file automatically, even if an error happens. The lab runs in the browser, so files live in WebAssembly's in-memory filesystem.

Show solution
n = int(input())
with open("notes.txt", "w") as f:
    for _ in range(n):
        f.write(input() + "\n")

with open("notes.txt") as f:
    for i, line in enumerate(f, 1):
        print(f"{i}: {line.rstrip()}")
Output
Answer
HOME LEARN COMMUNITY DASHBOARD