livepython.net

170. Python Program to Save a Name in a File and Read It Back

Easyopen()

Overview

Your first file program: open a file, write to it, close it, then open it again and read it.

Problem Statement

Read a name. Open a file called name.txt in mode "w", write Name: followed by the name, and close it. Then open name.txt again in mode "r", read the whole file, close it, and print what you read.

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

One line: a name. Example:

Sunny

Output

The text read back from the file:

Name: Sunny

The tests try 3 different names.

Learn this firstChapter 19 · Python open(): Open a File and Choose a File Mode
solution.py
# write your code here

EXPECTED OUTPUT

1Name: Sunny

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.