124k views
4 votes
Define a Python function named file_listers with two parameters. The first parameter will be a string specifying the name of the file to write to. The second parameter will be a list of str. Your function should open the file in a manner that erases its contents. For each entry in the second parameter, write it to the file and then a newline. Your function does not need to return anything.Example:list_2_file("empty.txt", []) creates a file named empty.txt but that file will be empty.list_2_file("simple.txt", ["Write", "me"]) creates a file named simple.txt which contains two lines of text. The first line has the text Write and the second line says me.

User Deleted
by
4.4k points

1 Answer

7 votes

Answer:

Check the explanation

Step-by-step explanation:

we can now create a file named simple.txt which contains two lines of text

below is the solution to the question:

def file_listers(filename,strlist):

name=raw_input(filename)

file = open(file, 'w')

with file as ≠:

for i in range(0, len(strlist) ):

f.write(strlist[i]+"\\")

file. close();

User Kintalken
by
4.7k points