Q. Write a program to remove all the lines that contain the character 'a' in this file and write other lines into another file.


Answer :-


myfile = open("Answer.txt", "r")
newfile = open("nswer.txt", "w")
line = ""
while line:
    line = myfile.readline()
    if 'a' not in line:
        newfile.write(line)

myfile.close()
newfile.close()
print("Newly created file contains")
print("------------")
newfile = open("nswer.txt","r")
line = ""
while line:
    line = newfile.readline()
    print(line)
newfile.close()


The output produced by above program is:-

Newly created file contains
------------

we know this will never occur.
How mediocre our world would be without this single most powerful letter.

Post a Comment

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

Previous Post Next Post