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