livepython.net

172. Python Program to Write a Shopping List to a File

EasyWrite

Overview

write() doesn't start a new line for you: add the "\n" yourself.

Problem Statement

Read one line with shopping items separated by spaces. Write each item into a file called shopping.txt, one item per line. Then open the file again, read it, and print what's 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 items, separated by spaces. Example:

bread milk eggs

Output

The file's text, one item per line:

bread
milk
eggs

The tests try 3 different lists, one of them with a single item.

Learn this firstChapter 19 · Python Write to File: write() and Append Mode
solution.py
# write your code here

EXPECTED OUTPUT

1bread
2milk
3eggs

YOUR OUTPUT

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