12 Practice Qns File Handling
(Text, Binary)
TEXT FILE HANDLING – Updated Practice Questions ---🔹 1.
Character-Based (Revised)📘 Focus: Read character by
character using read()1. Count the total number of non-
space characters in the file.2. Count how many digits,
alphabets, spaces, and special characters are present.3.
Ask user for a character and count its frequency.4. Extract
and display only punctuation marks used in the file.5.
Replace all vowels with # and store the result in
vowelmasked.txt.---🔹 2. Word-Based (Revised)📘 Focus: Use
read().split() to process words1. Count how many words
have more than 7 characters.2. Display all words that start
and end with the same letter.3. Create a new file with all
uppercase words from the original file.4. Count how many
words contain the letter 'z'.5. Find and display the second
most frequent word.---🔹 3. Line-Based (Revised)📘 Focus:
Use readlines() or iterate line by line1. Count how many
lines start with a capital letter.2. Display all lines that
contain a number (e.g., "Room 101").3. Count how many
lines end with a question mark.4. Display the longest line
(by character length).5. Copy only lines that do not
contain the word "error" to a new file.---🔹 4. Mixed-Type
(Revised)📘 Combination of character, word, and line
processing1. Print a report showing character count, word
count, and line count in the file.2. Count the number of
blank lines and lines with only spaces.3. Create a
frequency table of first letters of each word (e.g., A:5,
B:2...).4. Display all words that are repeated in multiple
lines.5. Create a summary that shows:Total linesLines
ending with '.'Words longer than 10 charactersMost used
special character---✅ BINARY FILE HANDLING – Updated
Practice Questions ---🔹 1. Record-Based (Revised)📘 Focus:
Handle multiple records using pickle.dump() and
pickle.load()1. Add a new employee record to a binary file
emp.dat.2. Display all records where employee salary >
50000.3. Count how many employees are from the
department 'IT'.4. Display records sorted by employee
name (alphabetically).5. Delete a record where employee
ID matches a user-given value.---🔹 2. List-Based (Revised)📘
Focus: Store and manipulate list objects1. Store a list of 10
temperatures and save to temp.dat.2. Read the list,
remove all duplicate values, and overwrite the file.3. Read
and display only even numbers from the stored list.4. Add
a new number at a user-given index and save again.5.
Display the list in reverse order without modifying the
original file.---🔹 3. Dictionary-Based (Revised)📘 Focus: Save
and update dictionary data1. Create and store a dictionary
{productID: productName} in prod.dat.2. Read the
dictionary and display all product names in uppercase.3.
Count how many products start with 'A' or 'B'.4. Update
the product name for a given product ID.5. Delete all keys
where product name length<4 and save again.---🔹 4.
Object-Based (Revised)📘 Focus: Create, store, search, and
update class objects1. Define a class Book (id, title, price)
and store 3 book objects.2. Display all book objects where
price > 500.3. Search and display a book with a user-given
title.4. Update the price of a book based on its ID.5. Delete
a book object whose title matches user input.---