Mar-22-2022, 08:50 PM
good evening,
could I ask for some help with this assignment?
so far I wrote:
can you please point out my mistake? also I'd like to use \n somewhere to make sure to store one word per line,maybe on third line of the function?
thanks in adavance,
Leyo
could I ask for some help with this assignment?
Quote:We want to save a list of words in a file so that we can reuse it later.
Define a function write_list_to_file(wordlst, filename) taking as parameters a list of words wordlst and a filename filename. The function should store the words in the list in a file (UTF8 encoding), one word per line.
so far I wrote:
wordlst=['walrus','cat','parrot','fish','monkey','giraffe'] #create a list of words def write_list_to_file(wordlst, filename): #define function with open("filename.txt","w") as myfile: #the file doesn't exist, so it should create one, open in write mode for word in wordlst: #for element in wordlst myfile.write(word) #write element in myfile print(write_list_to_file(wordlst,filename)) #nothing happens
can you please point out my mistake? also I'd like to use \n somewhere to make sure to store one word per line,maybe on third line of the function?
thanks in adavance,
Leyo