Question: python program make a sample .txt and how to write words that are longer than 5 characters into a new .txt file using while loop

 python program make a sample .txt and how to write words

python program make a sample .txt and how to write words that are longer than 5 characters into a new .txt file using while loop and if statement

. Practice file I/O. Please download the file named nouns.txt to the folder where your program is to reside. You are asked to write a program to read words from the file, and write to a different file only those words longer than 5 characters. In nouns.txt, each non-blank line contains exactly one word. The output file name can be results.txt. First of all, you want to open the file for reading. As long as end of file is not reached, your loop keeps reading words, one line at a time. Within the loop body, you check whether the length of the read is greater than 5; if so, write it to the output file, one word per line. Finally, don't forget to close the connections to both input and output files. Your program is expected to produce an output file with the following contents: banana elephant aquamarine anteater orange indigo purple

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!