The document outlines a series of Python programming tasks related to reading and processing text files. Tasks include counting occurrences of specific words, vowels, and characters, displaying lines based on length or starting letters, and writing reversed lines to a new file. Each task is designed to enhance file handling and string manipulation skills in Python.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views2 pages
CH 4 - File Handling Material For Board Exam
The document outlines a series of Python programming tasks related to reading and processing text files. Tasks include counting occurrences of specific words, vowels, and characters, displaying lines based on length or starting letters, and writing reversed lines to a new file. Each task is designed to enhance file handling and string manipulation skills in Python.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
3 – MARKS (TEXT FILE)
1. Write a method in Python to read lines from a text file
INDIA.TXT, to find and display the occurrence of the word 'India'. 2. Write a Python function which reads a text file “poem.txt” and prints the number of vowels in each line of that file, separately. 3. Write a method/function BIGLINES() in Python to read lines from a text file CONTENT.TXT, and display those lines, which are bigger than 20 characters. 4. Write a function COUNTTEXT( ), which reads a text file Book.txt and displays all the words of the file whose length is more than 3 or those which start with „A‟ or „a‟ . in the form of a list. For example, if the Book.txt file contains India is my country. They are studying. then the output should be: [“India”, “country”, “They”, “are”, “studying”] 5. Write a Python program that writes the reverse of each line in “input.txt” to another text file “output.txt”. Eg: if the content of input.txt is: The plates will still shift and the clouds will still spew. The content of “output.txt” should be: tfihs llits lliw setalp ehT .weps llits lliw sduolc eht dna 6. Write a function named COUNT_CHAR() in python to count and display number of times the arithmetic operators (+,-,*,/) appears in the file “Math.txt” . Example: Solve the following: 1.(A+B)*C/D 2.(A-B)*(A+B)/D-(E/F) 3. A+B+C/D*(E/F) The function COUNT_CHAR() must display the output as Number of „+‟ sign is 4 Number of „-„ sign is 2 Number of „*‟ sign is 3 Number of „/‟ sign is 5 7. Write a function V_COUNT() to read each line from the text file and count number of lines begins and ends with any vowel. 8. Write a user-defined function named Count() that will read the contents of text file named“Report.txt” and count the number of lines which starts with either "I" or "M". E.g. In the following paragraph, there are 2 lines starting with "I" or "M". 9. Write a function/method DISPLAYWORDS( ) in python to read lines from a text file STORY.TXT and display those words, which are less than 4 characters. 10. Write a function stats( ) that accepts a filename and reports the file‟s longest line. 11. Write a function countdigits() in Python, which should read each character of a text file “marks.txt”, count the number of digits and display the file content and the number of digits. Example: If the “marks.txt” contents are as follows: Harikaran:40,Atheeswaran:35,Dahrshini:30,Jahnavi:48 The output of the function should be: ('Total number of digits in the file:', 8) 12. Write a function in Python to count the number of lines in a text file „STORY.TXT‟which is starting with an alphabet „A‟. 13. Write a method SHOWLINES() in Python to read lines from text file TESTFILE.TXT„ and display the lines which do not contain 'ke'. 14. Write a function RainCount() in Python, which should read the content ofa text file ―TESTFILE.TXT‖ and then count and display the count of occurrenceof word RAIN (case- insensitive) in the file. Example: If the file content is as follows: It rained yesterday It might rain today I wish it rains tomorrow too I love Rain The RainCount() function should display the output as: Rain – 2 15. Define a function SHOWWORD () in python to read lines from a text file STORY.TXT, anddisplay those words, whose length is less than 5. 16. Write a user defined function in python that displays the number of lines starting with 'H' in the filepara.txt 17. Write a function in Python to print those words which contains letter „S‟ or „s‟ anywhere in the word in text file “STORY.txt” 18. Write a function COUNTLINES( ) which reads a text file STORY.TXT and then count anddisplay the number of the lines which starts and ends with same letter irrespective of itscase.