File Handling Program Questions
File Handling Program Questions
TXT
should count and display the occurrence of alphabets E and U (including small cases e and u too).
E:8
U:3
2. Write a Python program to find the longest word in file “status.txt”. If contents of status.txt are
Welcome to your one - step solutions for all your study, practice and assessment need for various
competitive and recruitment examinations and school segment. We have been working tirelessly for
over a decade to make sure that you have best in class study resources because you deserve
SUCCESS AND NOTHING LESS...
Output should be
3. Write a program in Python to open a text file “lines.txt” and display all those words whose length
is greater than 5.
4. Write a program to read the content from a text file “status.txt”, count and display the total
number of lines and blank spaces present in it. e.g. if the “status.txt” file contains the following lines:
Welcome to your one-step solutions for all your study, practice and assessment needs for various
competitive & recruitment examinations and school segment. We have been working tirelessly for
over a decade to make sure that you have best in class study resources because you deserve
SUCCESS AND NOTHING LESS...
5. Write a method countopen( ) to count and display the number of lines starting with the word
‘OPEN’ (including lower cases and upper cases) present in a text file “start. txt”.
6. Define a function in Python to accept a sentence and count the number of occurrences of the
word “is” and “was”.
Example
Output : No. of is : 2
No. of was : 1
7. Write a definition of a function that takes input a sentence and display the list of words that start
with a lowercase vowel and list of words that start with a uppercase vowel separately.
Example
Output
8. Write a method countFile() to count and display the number of lines starting with the word ‘FILE’
(including small cases and upper cases) present in a text file “start.txt”.
13. Print the words that begin and end with the same characters.
14. Print the words that begin and end with consonant.
17. Print the word that has the letter ‘e’ in it.
18. Print the words that has more than 5 characters in it.
19. Print the words that has more than 2 ‘t’ letters in it.
22. Count the number of ‘this’ present in a file. (THIS, THis, tHIS, all possible combination to
be included)
24. Print the lines that begin and end with same letter.
25. Print the lines that begin with the word ‘The’.(‘THE’, ‘THe’, ‘ThE’, all possible combination
to be included)
26. Print the lines that has more than 10 words in it.
27. Print the lines that has the characters ‘he’ in it. (‘he’ can be a separate word or can be a
part of word)
29. Count the number of characters present in each line of the file.
30. Count the number of words presen t in each line of the file.
32. Print the words that doesn’t have any vowels in it.
33. Print the lines that has more than 2 ‘is’ word in it.
34. Print the lines that has more than 3 four lettered words.
35. Copy the lines that has the word ‘that’ in it to a new file named “thatword.txt’
1.
11. Write a function SCOUNT( ) to read the content of binary file “NAMES.DAT‟ and return number
of records where name begins from “S‟ in it
1. Write a user defined function named display() to display the records and also the
2. Write a user defined function named totalsal() to display the sum of the salaries of all the
employees..
3. Write a user defined function named avgsalPurchase() to display the Average salary of
employees from “Purchase” department.
4. Write a user defined function named maleemployee() to display the names of all the male
employees.
5. Write a user defined function named salary() to display the name and salary of all the female
employees whose salary is more than 60000.
6. Write a user defined function named search(empid) which accepts empid as parameter and
searches and prints the record of the employee whose empid is given in the parameter.
7. Write a user defined function named copyPurchase() which copies the records of employees
who belong to “Purchase” department to a new file named “Purchase.dat”
8. Dicitonary Structure
9.