Connect with a global community of experts on IDNLearn.com. Ask anything and receive well-informed answers from our community of experienced professionals.

Given an initialized variable fileName, write a sequence of statements that create a file whose name is given by the variable and whose content is a single line consisting of "This Is File: " followed by the name of the file. Make sure that the data written to the file has been flushed from its buffer and that any system resources used during the course of running these statements have been released.

Sagot :

Answer:

In Python:

fileName = "myfile.txt"

fname = open(fileName, "w")

fname.write("This Is File: "+str(fileName))

fname.close()

Explanation:

This initializes fileName

fileName = "myfile.txt"

This creates the file in write mode

fname = open(fileName, "w")

This writes the required string to the file

fname.write("This Is File: "+str(fileName))

This closes the file

fname.close()

The program writes a given string into a newly created file with the name of the file concatenated to the end of string written into the file. The program is written in python 3 thus ;

fileName = 'text file.txt'

#stores the name of the file into a variable.

with open(fileName, 'w') as wrtfile:

#file is opened of in the write mode and is aliased.

wrtfile.write("This is file" + str(fileName))

#writes the string into the file and add the file name the end.

Learn more :https://brainly.com/question/15086326