please give the explanations! Thx! part 1 1l def saveList (myList, myPilename):
ID: 3708296 • Letter: P
Question
please give the explanations! Thx!
part 1
1l def saveList (myList, myPilename): 2 outputRile-open (myFilename, " 3 for item in myList: outputFile.write (item "n outputFile.close) 61 7| def loadList (myFilename) : 9 inputFile - open(myPilename, "r") 10 for line in inputFile: newList.append (line) 12 return newList Above are the definitions of a function that will save a list of strings to a file, and a function that will load a list from a file. However, they don't quite work as intended. Which of the following problems presently occurs? Every time the list is saved and then loaded, one item is lost because saveList) saves one too few items Every time the list is saved and then loaded, one item is lost because loadListo loads one too few items. Every time the list is saved and then loaded, extra blank lines are added between every list item Every time the list is saved and then loaded, any line breaks present are lost and the text is merged onto one line. Every time the list is saved and then loaded, the previous file is overwritten.Explanation / Answer
part 1
At line 4 everytime new item is added to the file blank line is also added to the file
so everytime file is saved and loaded extra blank lines are added between every list item so option 3 is answer where the problem occurs
part2
the problem can be solved by removing blank line by using strip()
so replace line 11 with
newList.append(line.strip())
option 5 is correct answer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.