feat(problem-03.py): completed problem.

This commit is contained in:
baphim
2026-09-13 09:50:30 -04:00
parent 0136c9aeb7
commit 264a89af65
+15
View File
@@ -1 +1,16 @@
# Write a Python program that opens a file and handles a FileNotFoundError exception if the file does not exist.
# Define open_file function to open files specified by user
def open_file(filename):
# Try to open entered filename
try:
open(filename)
except FileNotFoundError:
# Handle expected FileNotFoundError and print error message
print('That file cannot be found.')
except PermissionError:
# Handle PermissionError exception for file existing in directory used in problem-05.py
print('Insufficient permission to open file')
#Prompt user to enter a file name to be opened
open_file(filename = input('Enter the name of the file to open: '))