diff --git a/lab-02/problem-09.py b/lab-02/problem-09.py index 6f8518e..ca86169 100644 --- a/lab-02/problem-09.py +++ b/lab-02/problem-09.py @@ -1 +1,11 @@ -# Write a Python program that opens a file and handles a UnicodeDecodeError exception if there is an encoding issue. \ No newline at end of file +# Write a Python program that opens a file and handles a UnicodeDecodeError exception if there is an encoding issue. + +#Try opening the 'test.bin' file (which was created specifically for this problem) and assign it to 'f' +try: + with open('test.bin') as f: + # Attempt to read the 'test.bin' file + f.read() +# Handle the expected UnicodeDecodeError exception +except UnicodeDecodeError: + # Print the error message + print('There was an encoding problem with this file') \ No newline at end of file