8053775-XII - CS - Worksheet 4 - DATA FILES& CSV
8053775-XII - CS - Worksheet 4 - DATA FILES& CSV
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