Stuck on this school question, what am I missing?
"Objective: Complete the function to append the given new data to the specified file then print the contents of the file"
On of my many attempts:
import os
def appendAndPrint(filename, newData):
with open(filename, 'a') as f:
f = f.write(newData)
r = f.read()
print(r)
Test case, expected output: Hello World
with open("test.txt", 'w') as f:
f.write("Hello ")
appendAndPrint("test.txt", "World")
If I get the interpreter to not throw an error, on several attempts it would simply print 5.