Question: 1 1 . 1 5 LAB practice reading files Skills Reviewed open text file for reading read text data close file Instructions Write a python
LAB practice reading files
Skills Reviewed
open text file for reading
read text data
close file
Instructions
Write a python code file named readfileexercise.py
Your code should do the following:
ask the user for the name of a text file a shopping list
read the data in the text file lines of text
print the shopping list data
When printing the shopping list, there should be no blank lines
between items to be bought. You can use the rstrip function
to remove newline characters from the lines read from the data file.
Example
file name? shoppinglisttxt
Shopping List
bananas
cat food
paper towels
brownie mix
carrots
brussel sprouts
catfish fillets
Error Handling
If the file asked for by the user does not exist,
the program should not crash. It should instead
print an error message as shown below.
file name? shoppinglisttxt
ERROR: file shoppinglisttxt could not be read
One way to handle a file opening error is to use tryexcept
try:
file code goes here
open file
read file
close file
except:
error message code goes here
author: Monika JankunKelly
LAB
LAB : LAB practice reading files
Submission Instructions
Downloadable files
Download
Upload your files below by dragging and dropping into the area or choosing a file on your hard drive.
readfileexercise.py
Drag file here
or
Choose on hard drive.
Coding trail of your work What is this?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
