0% found this document useful (0 votes)
15 views17 pages

File Ijokk (Questions)

The document outlines various programming tasks related to handling text files in Python, including functions for reading, counting words, and displaying content in specific formats. It also discusses file modes, the seek() method, and provides examples of functions to manipulate text files. Additionally, it includes questions and exercises to reinforce understanding of file handling concepts.

Uploaded by

MANIK BANSAL 9C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views17 pages

File Ijokk (Questions)

The document outlines various programming tasks related to handling text files in Python, including functions for reading, counting words, and displaying content in specific formats. It also discusses file modes, the seek() method, and provides examples of functions to manipulate text files. Additionally, it includes questions and exercises to reinforce understanding of file handling concepts.

Uploaded by

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

DREAM TECHNOLOGY

File
Handling
Important Questions
Important Question of text file

Programming on Text file Example of text file


 count/search/update
 Char/words/line seek()and tell()

Text file vs binary file vs csv

file

Type of modes
Write a function Show_words( ) in python to read the content of a text file 3
‘NOTES.TXT” and display the entire content in capital letters. Example if the file
contains:
“This is a test file”
Then the function should display the output as:
THIS IS A TEST FILE
Write a function countmy( ) in python to read the text file “DATA.TXT” and
count the number of times “my” occurs in the file.
For example if the file “DATA.TXT” contains:

“This is my website. I have displayed my preferences in the CHOICE


section”

The countmy( ) function should display the output as : “my occurs 2 times”
Write a function in Python that counts the number of “Me” or “My”
words present in a text file “STORY.TXT”. If the “STORY.TXT”
contents are as follows:

My first book was Me and My family.

It gave me chance to be known to


the world. The output of the
function should be:
Count of Me/My in file:
What is the difference between r+ and w+ modes?

a. no difference
b. in r+ the pointer is initially placed at the beginning of the file and the pointer is at
the end for w+

c. in w+ the pointer is initially placed at the beginning of the file and the pointer is
at the end for r+

d. depends on the operating system


Write a method COUNT_DO() to count the presence of a word ‘do’ in a text file
“MEMO.txt”
Example:
If the content of the file is:
I will do it, if you request me to do it. It would have been
done much earlier.
Output should be : 2
Note: In the above example, ‘do’ occurring as a part of the word
done is not considered.
Write a method wordcount() which accepts the name of a text file and displays the
number of words present in the file which have the same first and last letter
(Ex: Pump, trot).
Which of the following statements correctly explain the function of seek() method?

a. Tell the current position within the file.

b. Indicate that the next read or write occurs from that position in a file.

c. Determine if you can move the file position or not.

d. Move the current file position to a different location at a defined offset


Write a method COUNTLINEVOWEL() in Python to read lines from text file ‘QUOTES.TXT’
and display the lines which are not starting with any vowel.

Example: If the file content is as follows:

The purpose of our lives is to be happy.


Always remember that you are absolutely unique.

The future belongs to those who believe in beauty of their dreams. The

COUNTLINEVOWEL() function should display the output as: The number of lines starting

with any vowel – 1


Write a function COUNT() in Python, which should read each character of a text file
‘QUOTES.TXT’ and then count and display the count of occurrence of alphabets E and S
individually (including small cases e and s too).
Example : If the file content is as follows:

The purpose of our lives is to be happy.


Always remember that you are absolutely unique.
The future belongs to those who believe in beauty of their dreams.

The COUNT() function should display output as: The number of E or e : 18


The number of S or s : 8
Write a function countmy( )in Python to read the text file “Data.txt” and count the number
of times “my” occurs in the file.
For example if the file “Data.txt” contains:

“This is my website.
I have displayed my preferences in the CHOICE section. You will get an idea of my
preferences from that section”

The countmy( ) function should return the count of ‘my’ from the file and program should
display the output as:
“my occurs 3 times in the file”.
If the following statement is used to read the contents of a text file object F:
x=F.readlines( )

Which of the following is the correct data type of x?

(a) String

(b) list

(c) tuple

(d) dictionary
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.

(OR)

Write a function to count the words He/She in a file.


Read the following Python code
carefully and fill in the blanks.
a. import pickle
infile =open(“phonebook..dat”,”______”)#Line 1
phonebook =__________(infile)#Line 2
print(phonebook)

b. with open(“content.txt”,”r”)
data=file1.____________(4)
if data[0]==‘w’
print(data)
• Write one difference between tell() and seek() functions with syntax.
• Differentiate between the following:
(i) f=open(‘data.txt’,’)
• A binary file “STUDENT.DAT” has the structure [admission_number, Name ,
Percentage ]. Write a function countrec() in python that would read contents of
the file “STUDENT.DAT” and display the details of those students whose
percentage is above 75. Also display number of students satisfying the same
condition.
• Find out the errors in the code below. Underline and rewrite corrected code
after removing syntax errors.
Import pickle
Data=[“One”,2,[3,4,6]]
with open (‘data2.dat’,’r’) as fill1:
pickle.dump(fill1,Data)

You might also like