100% found this document useful (1 vote)
33 views2 pages

8053775-XII - CS - Worksheet 4 - DATA FILES& CSV

The document contains 14 questions related to binary and CSV files in Python. The questions involve tasks like creating, reading, modifying and deleting records from binary and CSV files. Some questions require writing functions to search, count, add or remove records based on certain criteria.

Uploaded by

Jeevitha G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
33 views2 pages

8053775-XII - CS - Worksheet 4 - DATA FILES& CSV

The document contains 14 questions related to binary and CSV files in Python. The questions involve tasks like creating, reading, modifying and deleting records from binary and CSV files. Some questions require writing functions to search, count, add or remove records based on certain criteria.

Uploaded by

Jeevitha G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

INDIAN SCHOOL AL WADI AL KABIR

Class: XII Comp. Sci. Department: Computer Science

Worksheet No: 4 Topic: Data Files – BINARY FILES,CSV FILES Note:

1 A binary file “Book.dat” has structure [BookNo, Book_Name, Author, Price].


1. Write a user defined function CreateFile() to input data for a record and add to Book.dat .
2. Write a function CountRec(Author) in Python which accepts the Author name as parameter and
count and return number of books by the given Author are stored in the binary file “Book.dat

2 A binary file “STUDENT.DAT” has 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 scoring
above 75%.
3 Write a function in python to search and display details, whose destination is “Cochin” from binary file
“Bus.Dat”. Assuming the binary file is containing the following elements in the list:
1. Bus Number
2. Bus Starting Point
3. Bus Destination

4 Write a function addrec() in Python to add more new records at the bottom of a binary file
“STUDENT.dat”, assuming the binary file is containing the following structure :
[Roll Number, Student Name]

5 Write a function searchprod( pc) in python to display the record of a particular product from a file
product.dat whose code is passed as an argument. Structure of product contains the following elements
[product code , product price]
6 Write a function routechange(route number) which takes the Route number as parameter and modify
the route name(Accept it from the user) of passed route number in a binary file “route.dat”.
7 Write a program to display all the records from product.csv whose price is more than 300. Format of
record stored in product.csv is product id, product name, price,.

8 Write a function countrec(sport name) in Python which accepts the name of sport as parameter and
count and display the coach name of a sport which is passed as argument from the binary file
“sport.dat”. Structure of record in a file is given below ——————– – [sport name, coach name]
9 A binary file “salary.DAT” has structure [employee id, employee name, salary]. Write a function
countrec() in Python that would read contents of the file “salary.DAT” and display the details of those
employee whose salary is above 20000.

1| 28 - 0 8 - 2 0 2 2 / P R E P A R E D B Y : M r s . A N I L A B A L A G O P A L
10 Amit is a monitor of class XII-A and he stored the record of all the students of his class in a file named
“class.dat”. Structure of record is [roll number, name, percentage]. His computer teacher has assigned
the following duty to Amit
Write a function remcount( ) to count the number of students who need remedial class (student who
scored less than 40 percent)

11 A binary file “emp.dat” has structure [employee id, employee name]. Write a function delrec(employee
number) in Python that would read contents of the file “emp.dat” and delete the details of those
employee whose employee number is passed as argument.
12 Write a program to read all content of “student.csv” and display records of only those students who
scored more than 80 marks. Records stored in students is in format : Rollno, Name, Marks

13 Write a program to search the record from “data.csv” according to the admission number input from the
user. Structure of record saved in “data.csv” is Adm_no, Name, Class, Section, Marks

14
Rohit, a student of class 12th, is learning CSV File Module in Python.
During examination, he has been assigned an incomplete python code
(shown below) to create a CSV File 'Student.csv' (content shown below).
Help him in completing the code which creates the desired CSV File.
CSV File
1,AKSHAY,XII,A
2,ABHISHEK,XII,A
3,ARVIND,XII,A
4,RAVI,XII,A
5,ASHISH,XII,A
Incomplete Code
import_____ #Statement-1
fh = open(_____, _____, newline='') #Statement-2
stuwriter = csv._____ #Statement-3
data = []
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION']
data.append(header)
for i in range(5):
roll_no = int(input("Enter Roll Number : "))
name = input("Enter Name : ")
Class = input("Enter Class : ")
section = input("Enter Section : ")
rec = [_____] #Statement-4
data.append(rec)
stuwriter. _____ (data) #Statement-5
fh.close()

2| 28 - 0 8 - 2 0 2 2 / P R E P A R E D B Y : M r s . A N I L A B A L A G O P A L

You might also like