33 CSV File SQP
33 CSV File SQP
● CSV file: import csv module, open / close csv file, write into a csv file using csv.writer()
and read from a csv file using csv.reader( )
4. Count number of record in CSV file where Each record consists of a list
with field elements as empid, name , salary and dname to store
employee id, employee name, employee salary and employee
department name respectively.
Question 2:
A csv file “STUDENT.csv” has structure [admission_number, Name, stream,division]
i. Write a user defined function add() to input data for a record and add to “STUDENT.csv”.
ii. Write a function Count() in Python which count the number of student in the csv file “STUDENT.csv”
iii. Write a function CountRec() in Python which count and display student of Science stream are stored in the
csv file “STUDENT.csv”.
iv. Write a function Countfst() in Python which count and display student of get first division that are stored in
the csv file “STUDENT.csv”.
v. Write a function search() to search student by admission number (entered by user) from csv file
“STUDENT.csv”
Question 3:
A csv file “MEMBER.csv” has structure [M_number, M_Name, City]
i. Write a user defined function Createadd() to input data for a record and add to “MEMBER.csv”.
ii. Write a function Count() in Python which count the number of members in the csv file “MEMBER.csv”
iii. Write a function CountRec(city) in Python which accepts the city as parameter and count and display member
of that city are stored in the csv file “MEMBER.csv”.
Question 4:
A csv file GIFTS.csv has structure [ ID, Remarks, Price]
i. Write a user defined function CreateFile() to input data for a record and add to GIFTS.csv
ii. Write a function Count() in Python which count the number of gift in the csv file “GIFTS.csv”
iii. Write a function CountRec() in Python which count and display gifts of those gifts, which has remarks as “ON
DISCOUNT” are stored in the csv file GIFTS.csv
Question 5:
A csv file “LAPTOP.csv” has structure [ ModelNo, Brand , Price ]
i. Write a user defined function add() to input data for a record and add to “LAPTOP.csv”
ii. Write a function Count() in Python which count the number of Laptop in the csv file “LAPTOP.csv”
iii. Write a function CountRec(Brand) in Python which accepts the brand as parameter and count and display
laptop of that brand are stored in the csv file “LAPTOP.csv”
iv. Write a function in python to read and display the details of all the laptop which are priced between 40000
and 50000 from a csv file “LAPTOP.csv”, also display number of laptop are in this range.
Question 6:
A csv file “CUSTOMER.csv” has structure [ CNO, Cname, Gender]
i. Write a user defined function add() to input data for a record and add to “CUSTOMER.csv”.
ii. Write a function Count() in Python which count the number of customer in the csv file “CUSTOMER.csv”
iii. Write a function CountRec() in Python which count and display female customer that are stored in the csv file
“CUSTOMER.csv”
Question 7:
A csv file “CLUB.csv” has structure [ Mno, Mname, Type]
i. Write a user defined function add() to input data for a record and add to CLUB.csv
ii. Write a function Count() in Python which count the number of member stored in the csv file “CLUB.csv”
iii. Write a function search() that search a particular member by name from CLUB.csv file
iv. Write a function in python to read and display the details of all the users whose membership type is ‘L’ or ‘M’
from a csv file “CLUB.csv”, also display number of those members.
Question 8:
A csv file “FOOD.csv” has structure [ Fname, Region,Type]
i. Write a user defined function add() to input data for a record and add to FOOd.csv , enter veg for vegetarian
and nonveg for non-vegetarian
ii. Write a function Count() in Python which count the number of food stored in the csv file “FOOD.csv”
iii. Write a function CountRec() in Python which accept region as parameter and count and display food of those
region are stored in the csv file FOOD.csv
iv. Write a function in python to read and display the details of veg food from south from a csv file “FOOD.csv”,
also display number of food of this category.
Question 9:
A csv file “DOCTOR.csv” has structure [ Dname, Dept, Exp]
i. Write a user defined function add() to input data for a record and add to “DOCTOR.csv”.
ii. Write a function Count() in Python which count the number of doctor stored in the csv file “DOCTOR.csv”
ii. Write a function CountRec(Dept) in Python which accepts the department as parameter and count and display
doctor who are working in that department and having experience more than years, are stored in the csv file
“DOCTOR.csv” .
Question 10:
A csv file “ITEM.csv” has structure [ Iname, Cost_Price, Selling_Price]
i. Write a user defined function add() to input data for a record and add to “ITEM.csv”.
ii. Write a function CountRec(Selling_price) in Python which accepts the Selling_Pice as parameter and count and
return number of item whose selling price is more that price, are stored in the csv file “ITEM.csv” .
i. Write a function Countprt() in Python read contents of the file “ITEM.csv” and display details of item which are
sell on more than 25% profit. Also display number of items of this category.
Question 11:
A csv file “CLOTHS.csv” has structure [ Cid, Cname, Material, Gender]
i. Write a user defined function add() to input data for a record and add to “ITEM.csv”.
ii. Write a function Count(Material) in Python which accepts the Material as parameter and count and return
number of cloths of that material, are stored in the csv file “ITEM.csv” .
iii. Write a function countrec() in Python that would read contents of the file “CLOTHS.csv” and display the
details of cotton cloths for female. Also display number of cotton cloths for female.