1) Write a function Show_words() in Python to read the content of a text file 'NOTES.
TXT' and
display only such lines of the file which have exactly 5 words in them.
Example, if the file contains :
This is a sample file.
The file contains many sentences.
But needs only sentences which have only 5 words.
Then the function should display the output as :
This is a sample file.
The file contains many sentences.
2) A text file “WisdomQuotes.Txt” has the following data written in it:
Embrace challenges; they make you stronger.
Learn from yesterday, live for today, hope for tomorrow.
Your attitude determines your direction.
Believe you can and you are halfway there.
Write a user defined function to display the total number of words present in the file.
3) Write a Python function count_my() to read the text file "DATA.TXT" and count the number
of times the word "my" occurs in the file. For example, if the content of the file "DATA.TXT" is
updated to: “This is my Python program. I enjoy programming and customizing my code.”
The count_my() function should display the output as: "my occurs 2 times".
4) Write a method count_lines( ) in Python to read lines from text file ‘student.txt’ and
display the total number of line in file and lines which are ending with ‘y’ alphabet and
not ending with ‘y’ separately.
Example: If the file content is as follows:
An apple in a day keeps the doctor away.
We should aware for everyone’s safety and security.
India is one of the biggest country in word.
The count_lines( ) function should display the output as:
The number of lines in file are: 3
The number of lines ending with alphabet ‘y’ are: 2
The number of lines not ending with alphabet ‘y’ are: 1
5) Write a function VowelCount() in Python, which should read each character of a text file
MY_TEXT_FILE.TXT, should count and display the occurrence of alphabets vowels.
6) Write a function filter(oldfile, newfile) that copies all the lines of a text file “source.txt” onto
“target.txt” except those lines which starts with “@” sign.
7) Write a code in Python that replace of “The” to “This” words present in a text file
“MY_TEXT_FILE.TXT”.
8) Write a Python program to find the number of lines in a text file ‘abc.txt’.
9) Write a python function rev_text() which read from an existing text file content.txt and
creates another file, new.txt by copying all lines of content.txt with words starting with I
reversed.
Example is content.txt has:
The prisoners were taken to an isolated island
Nobody could identify them
New.txt should have
The prisoners were taken to an edtalosi dnalsi
Nobody could yfitnedi them.
10)
11)
12)
13)
14)
15)