[go: up one dir, main page]

0% found this document useful (0 votes)
75 views1 page

Practical - 2 Text Files

The document outlines 6 tasks to write Python functions that analyze text files: 1) Display sentences separately from a file, 2) Count uppercase and lowercase letters, 3) Display lines starting with a word, 4) Count vowels, 5) Display non-vowel starting lines, 6) Count occurrences of E/e and T/t letters.

Uploaded by

lakshanya8094
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views1 page

Practical - 2 Text Files

The document outlines 6 tasks to write Python functions that analyze text files: 1) Display sentences separately from a file, 2) Count uppercase and lowercase letters, 3) Display lines starting with a word, 4) Count vowels, 5) Display non-vowel starting lines, 6) Count occurrences of E/e and T/t letters.

Uploaded by

lakshanya8094
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Practical – 2 (Text files), 9 April

1 Write a UDF in Python named showInLines(), which reads the contents of a text file
named story.txt and displays every sentence in a separate line. Assume the sentence
ends with a “.” Or “!”.

For example:
Contents of story.txt:

Our parents told us that we must eat vegetables to be healthy. And it turns out, our
parents were right! So, what else did our parents tell?

OUTPUT:

Our parents told us that we must eat vegetables to be healthy.


it turns out, our parents were right!
So, what else did our parents tell?

2 Write a function c_words() in Python that separately counts and displays the number of
uppercase and lowercase alphabets in a text file “words.txt”
3 Write a function in Python to read a text file, Alpha.txt and displays those lines which
begin with the word ‘You’.
4 Write a function, vowel_count () in Python that counts and displays the number of
vowels in the text file named Poem.txt.
5 Write a method COUNTLINES() in Python to read lines from the text file ‘TESTFILE.TXT’
and display the lines which are not starting with any vowel.

Example:

If the file content is as follows:

An apple a day keeps the doctor away. We all pray for everyone’s safety. A marked
difference will come in our country.

The COUNTLINES() function should display the output as:

The number of lines not starting with any vowel – 1


6 Write a function ETCount() in Python, which should read each character of a text file
“TESTFILE.TXT” and then count and display the count of occurrence of alphabets E and T
individually (including small cases e and t too).

Example:

If the file content is as follows:

Today is a pleasant day. It might rain today. It is mentioned on weather sites

The ETCount() function should display the output as:

E or e: 6 T or t : 9

You might also like