I added extra lines of code to try my hand at the exercise. The code was meant to write to the file -which is successful- and then print the text file with the added lines instead it prints an integer (24) and after some changes it ow prints 25. What am I doing wrong?
Your additional three lines (47 -49) works.
There is also another way to do this:
new_file = open(input_file, 'a') new_file.write('Mary was sad afterwards.\n') new_file.close()
Of course you can put a variable inside the brackets “x.write(your_var)”.
This on line 50 “write_to_file(new_file)” looks like a function call.
But I do not see that definition.
I guess that you want the print at line 51 to print out.
You can do this.
new_file = open(input_file, 'r') print(new_file.read()) new_file.close() # it is better to close after working with the file.
Have a look at w3schools
I think they have good examples on how to do this and other things.
thanks a lot for the response it really helped me. I think the problem was not open the text file as readable after writing to it.
The “write_to_file” definition wasn’t captured in the screenshot.
Read up on seek and tell in this:
That should give you another clue.