Q. Write a program that reads a text file and creates another file that is identical except that every sequence of consecutive blank spaces is replaced by a single space.
You can understand by Watching video :-
Answer :-
file1 = open("Path Walla.txt","r") file2 = open("Portal Express.txt","w") lst = file1.readlines() for i in lst : word = i.split() file2.write( " ".join(word) ) file2.write("\n") print("Program has successfully run") file2.close() file1.close()
OR
file1 = open("portal.txt","r") file2 = open("Express.txt","w") lst = file1.readlines() for i in lst : word = i.split() for j in word : file2.write( j + " ") file2.write("\n") print("Program has successfully run") file2.close() file1.close()
Path Walla.txt Contains :-
This is the Path Walla Website. We are going to do some Python code Like a joy on the heart of a sorrow, The sunset hangs on a cloud; A golden storm of glittering sheaves, Of fair and frail and fluttering leaves, The wild wind blows in a cloud. Hark to a voice that is calling To my heart in the voice of the wind: My heart is weary and sad and alone, For its dreams like the fluttering leaves have gone, And why should I stay behind?
Output :-
Program has successfully run
>>>
Portal Express.txt Contains :-
This is the Path Walla Website. We are going to do some Python code Like a joy on the heart of a sorrow, The sunset hangs on a cloud; A golden storm of glittering sheaves, Of fair and frail and fluttering leaves, The wild wind blows in a cloud. Hark to a voice that is calling To my heart in the voice of the wind: My heart is weary and sad and alone, For its dreams like the fluttering leaves have gone, And why should I stay behind?
when i run tthe program it says FileNotFoundError: [Errno 2] No such file or directory: 'portal.txt'
ReplyDeleteplease make 'portal.txt' file in your computer then run the program...
DeleteYou may had not created it as u are opening in read so you must had this file in your pc
Deletethis is a common and mostly ocurring doubt,, u have to give full path of the file in header..go to the location where u have saved your file and right click on it and then click on properties , then copy the file path and paste it into the program file header.
DeleteIf ..it..is.. English...it . Would be..better
ReplyDelete???????? What do you want to Say... ??????
DeleteThe output show error
ReplyDeletePlease make portal.txt file in your system.
Deletethis answer is wrong because the same answer is for Q1
ReplyDeleteThis is correct answer, Question no. 13 and 1 are same.
DeleteThe target file is empty for me. I tried various times though there was no error.
ReplyDeletePlease write something in portal.txt file.
Deleteplease correct your spelling of help
ReplyDelete??
DeleteIt works well. Thank you.
ReplyDeleteWelcome : )
DeleteCan you plz give me the Python of Sumita Arora book pdf.
ReplyDeleteYou can download it from telegram.
Deletebro plz give correct question it is differenr from 1st one.
ReplyDeleteTell me problem.
DeleteIsn't this the answer of Q1?
ReplyDeleteWhat do you want say ???
DeleteHey, so how we can make the protal.txt file , by writing anything????
ReplyDeletePlease watch the video.
Deletebye
ReplyDeleteBro the question of 13 is different .
ReplyDeleteQ13) write a program that will create an object called filout for writing , associate it with the filename "STRS.TXT" .The code should keep on writing strings to it as long the user wants.
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )