Programming-Challenges/31 Error Handling/exercise-3.py
2026-08-31 14:34:15 +01:00

15 lines
520 B
Python

def writeFile():
"""write data to a file"""
try:
myFile = open('new_file.txt', 'w')
myFile.write("Little Bo Peep has lost her sheep")
myFile.write("\n")
myFile.write("And doesn't know where to find them.")
myFile.write("\n")
myFile.close()
except FileNotFoundError:
print("Error: The file could not be created.")
except IOError:
print("Error: There was an issue writing to the file.")
finally:
print("File operation completed.")