Text file reading writing searching and counting Theory part 2
Text file reading writing searching and counting
PYQ reference preview17 included1 excluded
Review every matched question before generating. Flag a wrongly categorised question to
quarantine it from both study and PPT prompts until it is corrected in CBSE Paper Analyzer.
Included in reference
ID 6125 · 2023 · 5 mark(s)
(a) Write one difference between CSV and text files.
Write a program in Python that defines and calls the following user defined functions :
(i) COURIER_ADD(): It takes the values from the user and adds the details to a csv file 'courier.csv'. Each record consists of a list with field elements as cid, s_name, Source, destination to store Courier ID, Sender name, Source and destination address respectively.
(ii) COURIER_SEARCH() : Takes the destination as the input and displays all the courier records going to that destination.
(ii) Search_Book(): Takes publisher name as input and counts and displays number of books published by them.
File Handling
→ CSV file read write and search, Text file reading writing searching and counting
· Concept U1_CSV_OPS;U1_TEXT_FILE_OPERATIONS
(a) Write a point of difference between append (a) and write (w) modes in a text file.
Write a program in Python that defines and calls the following user defined functions :
(i) Add_Teacher() : It accepts the values from the user and inserts record of a teacher to a csv file "Teacher.csv". Each record consists of a list with field elements as T_id, Tname and desig to store teacher ID, teacher name and designation respectively.
(ii) Search_Teacher() : To display the records of all the PGT (designation) teachers.
(ii) Count_Device() : To count and display number of peripheral devices, whose price is less than or equal to 1000.
Which of the following file opening mode is used to open a file in append and read mode ?
(A) r+
(B) w+
(C) a+
(D) x+
File Handling
→ File basics paths modes seek and tell, Text file reading writing searching and counting
· Concept U1_FILE_BASICS_MODES;U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6158 · 2024 · 3 mark(s)
(a) Write the user defined function count_words() in Python to count the number of words in a text file "Story.txt".
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6159 · 2024 · 3 mark(s)
(b) Write the user defined function display() in Python to read the content of a text file "Story.txt" and display those words which are less than 4 characters.
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6358 · 2024 · 3 mark(s)
(a) Write a method/function COUNTWORDS() in Python to read contents from a text file DECODE.TXT, to count and return the occurrence of those words, which are having 5 or more characters.
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6359 · 2024 · 3 mark(s)
(b) Write a method/function COUNTLINES() in Python to read lines from a text file CONTENT.TXT, and display those lines, which have @ anywhere in the line.
For example :
If the content of the file is :
Had an amazing time at the concert last night with
@MusicLoversCrew.
Excited to announce the launch of our new website!
G20 @ India
The method/function should display
Had an amazing time at the concert last night with
@MusicLoversCrew
G20 @ India
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6646 · 2024 · 3 mark(s)
A) Write a Python function that displays all the words containing @cmail from a text file "Emails.txt".
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6647 · 2024 · 3 mark(s)
B) Write a Python function that finds and displays all the words longer than 5 characters from a text file "Words.txt".
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6172 · 2024 · 4 mark(s)
Write a program in Python to read the content of a text file Story.txt and count and display the number of lines that start with the letter 'A'.
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6366 · 2024 · 5 mark(s)
(b) (i) Give one difference between write() and writeline() function in text file.
(ii) A Binary file, "Items.dat" has the following structure :
[Icode, Description, Price]
Where
Icode – Item code
Description – Detail of item
Price – Price of item
Write a function Add_data(), that takes Icode, Description and Price from the user and writes the information in the binary file "Items.dat".
A text file 'song.txt' contains the following contents in it :
Life goes on as it never ends
What will be the output of the following code snippet ?
f1=open("song.txt","r")
s1=f1.read(5)
s2=f1.readline(4)
s3=f1.read(3)
print(s1,s3,sep="#")
(A) goes# on
(B) Life #goes# on
(C) Life # on
(D) Error
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6203 · 2025 · 3 mark(s)
Write a user defined function in Python named COUNT() which counts and displays the number of lines which do not start with the vowels 'A' or 'E' in the file, "Paragraph.txt".
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6406 · 2025 · 3 mark(s)
(b) Write a function in Python to display the line which has the maximum number of vowels from a text file, "Novel.txt"
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6694 · 2025 · 3 mark(s)
A. Write a Python function that displays the number of times the word "Python" appears in a text file named "Prog.txt".
File Handling
→ Text file reading writing searching and counting
· Concept U1_FILE_BASICS_MODES;U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6695 · 2025 · 3 mark(s)
B. Write and call a Python function to read lines from a text file STORIES.TXT and display those lines which doesn't start with a vowel (A, E, I, O, U) irrespective of their case.
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6253 · 2026 · 3 mark(s)
(a) Write a Python function that counts and returns the number of digits appearing in the text file "Space.txt". For example, if the file contains :
Space exploration has unlocked incredible
advancements in technology and science. Since the
first moon landing in 1969, space agencies have sent
probes to Mars, Jupiter and beyond. The ISS,
orbiting Earth at about 400 km, serves as a hub for
research. With missions planned for 2030, humanity's
cosmic journey continues!
Then the function should return 11.
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Included in reference
ID 6254 · 2026 · 3 mark(s)
(b) Write a Python function that displays the words in which the lowercase letter 'e' appears at least twice in the text file 'Space.txt'. For example, if the file contains :
Space exploration has unlocked incredible
advancements in technology and science. Since the
first moon landing in 1969, space agencies have sent
probes to Mars, Jupiter and beyond. The ISS,
orbiting Earth at about 400 km, serves as a hub for
research. With missions planned for 2030, humanity's
cosmic journey continues!
Then the function should display :
incredible advancements science. agencies serves research.
File Handling
→ Text file reading writing searching and counting
· Concept U1_TEXT_FILE_OPERATIONS
Pick a lecture from the panel on the left, configure the board and student level,
then click Generate Prompt. The result includes PYQ data,
frequency analysis, exam trends, and a full 15-section teaching package request —
ready to paste into any AI assistant.
ChatGPTClaudeGeminiDeepSeek
PYQ Analysis
Frequency, marks & high-yield concepts
Lecture Flow
Exact time-allocation plan
15 Sections
From objectives to ranked exam questions
Export
Copy or download as .txt
Reset All Progress?
This will clear all Done and Missed marks and rebuild the schedule from scratch.
A backup will be created automatically before resetting. You can restore it from the Backups page.