Question: 1 . Copy step _ 1 . py to step _ 2 . py to use as a starting point. 2 . Store the name

1. Copy step_1.py to step_2.py to use as a starting point.
2. Store the name of the text file in a variable.
3. Use a try/except/else block to open the file.
4. If a FileNotFoundError exception is thrown, display a message to the user indicating that the file could not be found and quit the program with the quit() function. If this happens, it's either because the text file is not in the same folder as your program file or there's a spelling error in the file name.
5. In the else block, which we only get to if we have successfully opened the file:
Read and discard the first line of the file using readline(). This is the column heading line and we don't need it.
In a for loop, read each line of the file and strip the trailing line break. Split the line using the split() method and a tab as the delimiter, "\t".
The split should return three fields, which are the values for the timestamp, the name and the comment.
Create a dictionary with keys of "date", "name" and "timestamp" and use the values provided by the strip() call.
Append the dictionary to the records list.
6. Test your program.
First choose Menu Selection 1. You should see each record from the file displayed.
Choose Menu Selection 2 and add another entry.
Choose Menu Selection 1 again and you should see the original records, along with the one you have added.
7. Note that if you run the program again, none of the new records you entered via Menu Selection 2 will show because we haven't updated the text file. That's part of the final step.
8. If everything goes as planned, take a bow! Well done!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!