Q. What is the output of the following code fragment? Explain.

 
fout = file ("output.txt", 'w')
fout.write("Hello world! \n")
fout.write("How are you?")
fout.close()
file("output.txt").read()

Output :-

    fout = file ("output.txt", 'w')
NameError: name 'file' is not defined

It will give above Error.

So, I think Correct program should be :-

fout = open ("output.txt", 'w')
fout.write("Hello world! \n")
fout.write("How are you?")
fout.close()
file = open("output.txt").read()
print(file)

Output :-

Hello world!
How are you?

>>> 


4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post