Foundations of Programming (Python) Labs
LAB 05-A: Working with Files and Lists
In this Lab, you’ll be working with lists and files: Complete the starter code to read and write data from list to file.
We will be re-visiting the CD Inventory application throughout this course. Either use below examples or two of your own to complete this Lab.
| Artist | Title |
|--------|-------|
| Runrig | The Big Wheel |
| Michael Jackson | Bad |
Hint: Use a 2D list to hold the data.
- Review the code and make some notes about what it is trying to accomplish.
- Create the starter script as Lab05_A.
- Add to the header
- Replace the TODOs with your solution for the task stated.
- Test your script.
Example output of the script working:
Write or Read file data.
[a] add data to list
[w] to write data to file
[r] to read data from file
[d] display data
[exit] to quit
a, w, r, d, or exit: a
Enter the CDs Artist: Runrig
Enter the CDs Title: The Big Wheel
[a] add data to list
[w] to write data to file
[r] to read data from file
[d] display data
[exit] to quit
a, w, r, d, or exit: a
Enter the CDs Artist: Michael Jackson
Enter the CDs Title: Bad
[a] add data to list
[w] to write data to file
[r] to read data from file
[d] display data
[exit] to quit
a, w, r, d, or exit: w
[a] add data to list
[w] to write data to file
[r] to read data from file
[d] display data
[exit] to quit
a, w, r, d, or exit: r
[a] add data to list
[w] to write data to file
[r] to read data from file
[d] display data
[exit] to quit
a, w, r, d, or exit: d
Artist, Title
Runrig, The Big Wheel
Michael Jackson, Bad
[a] add data to list
[w] to write data to file
[r] to read data from file
[d] display data
[exit] to quit
a, w, r, d, or exit: exit
Example Text File created:
Back to self guided, Video only Materials
Back to self guided, Video plus Written Materials
Back to guided, Video plus Written Materials plus Personal Guidance, Feedback, and Support (class setting)