Question: Run this program in PyCharm, and then answer the following questions. my_file = open( nonsense.txt , w ) for i in range(6): line = input(
Run this program in PyCharm, and then answer the following questions.
my_file = open("nonsense.txt", "w") for i in range(6): line = input("Enter some text: ") my_file.write(line) my_file.close() print("HERE IS WHAT THE FILE LOOKS LIKE:") my_file = open("nonsense.txt", "r") line = " " while line != "": line = my_file.readline() print(line) my_file.close()
(a) Notice what the program says the file looks like after you wrote to it, and are now reading from it. Also, open the file by clicking on it in the PyCharm navigation bar. Evidently everything is packed into a single line. Why?
(b) Change my_file.write(line) to my_file.write(line + " "), and try again. What does the program now say the file looks like? What does it look like when you click on the file in the PyCharm navigation bar? How and why are the results different than in part (a)
(c) In part (b), the two views of the file don't quite agree. What is the difference? Explain why the program's display of the file is longer. What is wrong with this?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
