0% found this document useful (0 votes)
243 views

File Handling Program Questions

File Handling Program Questions

Uploaded by

clutchforever999
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
243 views

File Handling Program Questions

File Handling Program Questions

Uploaded by

clutchforever999
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1. Write a function countEU() in Python, which should read each character of a text file. IMP.

TXT
should count and display the occurrence of alphabets E and U (including small cases e and u too).

e.g. If the file content is as follows :

Pinaky has gone to his friend’s house.

His friend’s name is Ravya. Her house is 12 km from Pinaky’s house.

The countEU() function should display the output as:

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

Longest word : examinations

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...

The output will be:

The status file contents are

Total lines in file are: 4

Total spaces in file are: 43

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”.

e.g. If the file “start.txt” contains the following lines:

Get the data value to be deleted,

Open the file for reading from it.

Read the complete file into a list

Delete the data from the list

Open the file


Open same file for writing into it

Write the modified list into file.

Close the file.

The method should display

Total lines started with word ‘OPEN’ is/are: 3

6. Define a function in Python to accept a sentence and count the number of occurrences of the
word “is” and “was”.

Example

Input : “He is a good boy. She was and is a good girl”

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

Input : A quick black elephant enters Into a jungle.

Output

List of words starting with lowercase vowels [‘elephant’, ‘enters’, ‘a’]

List of words starting with uppercase vowels [‘A’, ‘Into’]

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”.

e.g. If the file “start.txt” contains the following lines:

Get the data value to be deleted,

Open the file for reading from it.

Read the complete file into a list

Delete the data from the list

Open the file

Open same file for writing into it

Write the modified list into file.

Close the file.

The method should display

Total lines started with word ‘FILE’ is/are: 0

9. Count number of ‘S’ or ‘T’ from a text file.


10. Count number of Vowels, Consonants, Spaces, Digits and Special characters from a text file.

11. Print the words that begin vowel

12. Print the words that begin the H or R

13. Print the words that begin and end with the same characters.

14. Print the words that begin and end with consonant.

15. Print the words that end with a digit

16. Print the three lettered words from a file

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.

20. Count the number of words present in the file.

21. Count the words that begin the K or ‘k’

22. Count the number of ‘this’ present in a file. (THIS, THis, tHIS, all possible combination to

be included)

23. Print the lines that begin with the letter T or W.

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)

28. Count the number of lines present in a file.

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.

31. Count the number of ‘e’ present in each line.

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

File Name : employee.dat

Structure - [empid, name, gender, dept, salary]

1. Write a user defined function named display() to display the records and also the

number of records from the file.

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

File Name : emp.dat

Structure – {empid:[ name, gender, dept, salary] }

9.

You might also like