0% found this document useful (0 votes)
374 views1 page

File Handling Assignment

The document provides instructions for several file handling tasks in Python. It includes creating and reading binary files, counting characters in text files, adding and retrieving records from data files, and reading data from a CSV file. Functions are to be written to accomplish tasks like adding to and reading binary and text files, counting characters and words, and filtering CSV data.

Uploaded by

Shikha Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
374 views1 page

File Handling Assignment

The document provides instructions for several file handling tasks in Python. It includes creating and reading binary files, counting characters in text files, adding and retrieving records from data files, and reading data from a CSV file. Functions are to be written to accomplish tasks like adding to and reading binary and text files, counting characters and words, and filtering CSV data.

Uploaded by

Shikha Jain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

Assignment on File handling for class XII

1) A binary file bank.dat has structure account_no, cust_name, balance 5


(a) Create a user defined function addfile() and add a record to binary file bank.dat
(b) Create a user defined function count() and count and return the number of customers
whose balance amount is more than 200000
2) Rohit wants to create a binary file containing data of students (rollno and name) . He has written
the following code. Study code and give answers of questions given below: 5
import ___________ (1)
def createfile(rollno,name)):
L=[rollno,name]
F=open(“stu,dat”,___) (2)
pickle.dump(____,F)
F.__________ (3)
def readfile():
with open(“stu,dat”,r) as newf:
while True:
data=pickle._____(newf) (4)
print(data)

createfile(1,”Anya”)
createfile(2,”Akshita”)
createfile(3,”Krish”)
readfile() (5)
1) Name the module that should be import in line 1
2) In which mode file should be opened to add new data in file stu.dat
3)Fill in the blank in line 3 for closing the file
4)Fill in the blank in line 4 for reading content of binary file
5)Write the output after execution of line 5

3) Write a pyton function countThisThat() to count all “this” and “that” (small cases only) from text
file story.txt and print number of “this” and “that” separately 3

4) Write a python function EndingWithr() to count number of lines from a text file myfile.txt which
are ending with ‘r’ (small letter only) 3

5) Write a python function CountLength4() to read the content of file poem.txt and count and return
those words which are of 4 characters or more 3

6) Write a python function countchar() to read the entire content of file drama.txt and count number
of visible characters in file ( excluding spaces and EOL character) 3

7) There is a file empdata.dat on disk with structure empid,empname and having some data
a) Write a python function adddata()to add two more records in file empdata.dat after taking input
from user and without deleting the previous records
b)Write a python function readCSV() to read the content of file emp.csv and display the data of
those employees whose names start with “S” (Capital only) 4

You might also like