File Handling
File Handling
[Set – 1]
1. Write a function in python to read the content from a text file "poem.txt" line by line
and display the same on screen.
2. Write a function in python to count the number of lines from a text file "story.txt"
which is not starting with an alphabet "T".
Example: If the file "story.txt" contains the following lines: A boy is playing there.
There is a playground.
An aeroplane is in the sky.
The sky is pink.
Alphabets and numbers are allowed in the password.
3. Write a function in Python to count and display the total number of words in a text
file.
4. Write a function in Python to read lines from a text file "notes.txt", to find and display
the occurrence of the word "the".
5. Write a function display_words() in python to read lines from a text file "story.txt", and
display those words, which are less than 4 characters.
6. Write a function in Python to count the words "this" and "these" present in a text file
"article.txt". [Note that the words "this" and "these" are complete words]
7. Write a function in Python to count words in a text file those are ending with alphabet
"e".
Example :
If the file matter.txt has the following content stored in it :
THE WORLD IS ROUND
10. Aditi has used a text editing software to type some text. After saving the article as
WORDS.TXT, she realised that she has wrongly typed alphabet J in place of alphabet I
everywhere in the article.
Write a function definition for JTOI() in Python that would display the corrected version
of entire content of the file WORDS.TXT with all the alphabets "J" to be displayed as an
alphabet "I" on screen.
Note: Assuming that WORD.TXT does not contain any J alphabet otherwise.
Example:
If Aditi has stored the following content in the file WORDS.TXT:
WELL, THJS JS A WORD BY JTSELF. YOU COULD STRETCH THJS TO BE A SENTENCE
The function JTOI() should display the following content:
WELL, THIS IS A WORD BY ITSELF. YOU COULD STRETCH THIS TO BE A SENTENCE
11. Given a pickled file employee.dat, created using dictionary object having keys:
(empcode, name, and salary)
1. Write a python function that add one more record at the end of file.
2. Write a python function that display all employee records whose salary is more that 30000
12. Write a function to search and display details of student whose rollno is ‘1005’ from
the pickled file student.dat. Assume that the file student.dat is created with the help of
dictionary object having information rollno, name, class and fees.
13. Assume that the pickled file school.dat is created with the help of dictionary objects
which keys are given below:
14. Given a pickled file players.dat, containing records of following list format: [code,
name, country and total runs]
1. Write a python function that display all records where player name starts from 'A'
2. Write a python function that accept country as an argument and count and display the number of
players of that country.
3. Write a python function that add one record at the end of file.
Write a function in Python that would read contents from the file game.dat and creates
a file named basket.dat copying only those records from game.dat where the game
name is "Basket Ball"