livepython.net

171. Python Program to Copy a Text File

Mediumopen()

Overview

Use the right file mode for each job: one file to read from, another to write to.

Problem Statement

Read one line of text and write it into a file called original.txt. Then copy the file: read everything in original.txt and write it into a new file called copy.txt. Finally, read copy.txt and print two lines:

  • Copy: followed by the text in copy.txt.
  • Characters: followed by the number of characters in it.

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 of text. Example:

Hello, Sunny!

Output

The output for that example:

Copy: Hello, Sunny!
Characters: 13

The tests try 3 different inputs.

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

EXPECTED OUTPUT

1Copy: Hello, Sunny!
2Characters: 13

YOUR OUTPUT

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