Programming Assignment Unit 8
Programming Assignment Unit 8
Ayesha Gul
Dr Josiah Jolaoluwa
File handling in Python allows data to be stored persistently, enabling long-term data
management beyond the program's runtime. This assignment demonstrates the process of reading
a dictionary from a file, processing it to invert the key-value pairs, handling exceptions, and
writing the modified dictionary to another file. Exception handling ensures that file-related
errors, such as missing files or incorrect formatting, do not crash the program. By implementing
this approach, we enhance data organization, improve retrieval efficiency, and ensure robust
Input:
3
Programming Assignment Unit 8
Output:
Explanation:
c. Exception handling ensures the program does not crash due to missing files or
incorrect formatting.
b. Values become keys, and keys are grouped as a list under them.
d. This process ensures multiple keys can be associated with the same value
efficiently.
output file.
This Python program successfully reads, processes, and writes dictionary data while
incorporating robust error handling mechanisms. Exception handling ensures that missing files,
incorrect formats, or unexpected issues do not cause the program to crash. By inverting the
dictionary, we restructure the data for better organization, making it easier to retrieve
information. This approach not only improves data management but also enhances efficiency in
Downey, A. (2015). Think Python: How to Think Like a Computer Scientist (2nd ed.). Green Tea
Press.
Schafer, C. (2016, April 29). Python tutorial: File objects - Reading and writing to files [Video].
YouTube. https://youtu.be/Uh2ebFW8OYM