190760-XII - CS - Worksheet 4 - DATA FILES& CSV
190760-XII - CS - Worksheet 4 - DATA FILES& CSV
190760-XII - CS - Worksheet 4 - DATA FILES& CSV
Worksheet No: 4 Topic: Data Files – BINARY FILES & CSV Note:
FILES
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 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]
8 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.
9 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)
10 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.
11 Write a program to read all content of “student.csv” and display records of only those students who
1| 08 - 0 8 - 2 0 2 3 / P R E P A R E D B Y : M r s . J E S N A J O S E
scored more than 80 marks. Records stored in students is in format : Rollno, Name, Marks. Use
functions to get data (getdata()) from the user and displaydata() to display students scored more than 80
marks.
12 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. Use functions to
get data from the user(accept()) and for searching the record(search())
13 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. Use functions to get data from the
user(accept()) and for displaying the data(display())
2| 08 - 0 8 - 2 0 2 3 / P R E P A R E D B Y : M r s . J E S N A J O S E