From 968ce1621da49874e2b86b7e4a04ecb970124297 Mon Sep 17 00:00:00 2001 From: baphim <269010393+baphim@users.noreply.github.com> Date: Mon, 14 Sep 2026 16:22:54 -0400 Subject: [PATCH] feat: completed problem-09.py --- lab-02/problem-09.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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