def addData(data):
try:
if isinstance(data, str):
with open("data.txt", "a") as file:
file.write(data + "\n")
return "Done"
else:
raise TypeError("Type error")
except FileNotFoundError:
return "Error: File not found."
except PermissionError:
return "Error: Writing to file"
except Exception as e:
return str(e)
returnValue = addData("The larch")
print(returnValue)
returnValue = addData(123)
print(returnValue)
Monty
Python