CSV file read, write and search PYQ part 3
PYQ PRACTICE SCOPE: CSV file read, write and search.
Concept ID: U1_CSV_OPS.
Use only previous-year questions whose concept_ids include U1_CSV_OPS.
Key things we'll cover
CSV file read, write and search
PYQ references used by both prompts8 included1 excluded
Flagged questions are excluded from both Study Notes and PPT references until corrected in Paper Analyzer.
Included
ID 6490 · 2021 · 1 mark(s)
Syntax for opening Student.csv file in write mode is myfile = open("Student.csv","w",newline='').
What is the importance of newline=''?
a) A newline gets added to the file
b) Empty string gets appended to the first line.
c) Empty string gets appended to all lines.
d) EOL translation is suppressed
File Handling → File basics paths modes seek and tell, CSV file read write and search
Included
ID 6526 · 2021 · 1 mark(s)
Choose the function name that should be used in the blank space of line marked as Statement-6 to create the desired CSV File.
(Refer to the CSV file creation code in the case study: stuwriter._____(data))
a) dump()
b) load()
c) writerows()
d) writerow()
File Handling → CSV file read write and search, Binary file operations with pickle
Included
ID 6566 · 2022 · 5 mark(s)
Give any one point of difference between a binary file and a csv file.
Write a Program in Python that defines and calls the following user defined functions:
(i) add() – To accept and add data of an employee to a CSV file 'furdata.csv'. Each record consists of a list with field elements as fid, fname and fprice to store furniture id, furniture name and furniture price respectively.
(ii) search() – To display the records of the furniture whose price is more than 10000.
File Handling → CSV file read write and search, Binary file operations with pickle
Included
ID 6125 · 2023 · 5 mark(s)
(a) Write one difference between CSV and text files.
Write a program in Python that defines and calls the following user defined functions :
(i) COURIER_ADD(): It takes the values from the user and adds the details to a csv file 'courier.csv'. Each record consists of a list with field elements as cid, s_name, Source, destination to store Courier ID, Sender name, Source and destination address respectively.
(ii) COURIER_SEARCH() : Takes the destination as the input and displays all the courier records going to that destination.
(ii) Search_Book(): Takes publisher name as input and counts and displays number of books published by them.
File Handling → CSV file read write and search, Text file reading writing searching and counting
Included
ID 6322 · 2023 · 5 mark(s)
(b) Write one point of difference between seek() and tell() functions in file handling.
Write a program in Python that defines and calls the following user defined functions :
(i) Add_Device() : The function accepts and adds records of the peripheral devices to a csv file 'peripheral.csv'. Each record consists of a list with field elements as P_id, P_name and Price to store peripheral device ID, device name, and price respectively.
(ii) Count_Device() : To count and display number of peripheral devices, whose price is less than or equal to 1000.
File Handling → File basics paths modes seek and tell, CSV file read write and search
Excluded
ID 6166 · 2024 · 5 mark(s)
Write a user defined function in Python named write_data() to write the data in a CSV file Stock.csv with field names Product_Name, Product_ID, Quantity, Price as shown below:
| Product_Name | Product_ID | Quantity | Price |
|--------------|------------|----------|-------|
| Keyboard | P101 | 10 | 800 |
| Mouse | P102 | 12 | 600 |
| Monitor | P103 | 5 | 5000 |
| CPU | P104 | 8 | 10000 |
(ii) pop_record(): To pop the elements from the stack and display. Also display "No Record" when there are no elements in the stack.
Stack Data Structure → CSV file read write and search, Stack concept and operations using list
Awaiting categorisation review
Included
ID 6701 · 2025 · 4 mark(s)
Raj is the manager of a medical store. To keep track of sales records, he has created a CSV file named Sales.csv, which stores the details of each sale.
The columns of the CSV file are: Product_ID, Product_Name, Quantity_Sold and Price_Per_Unit.
Help him to efficiently maintain the data by creating the following user-defined functions:
I. Accept() – to accept a sales record from the user and add it to the file Sales.csv.
II. CalculateTotalSales() – to calculate and return the total sales based on the Quantity_Sold and Price_Per_Unit.
File Handling → CSV file read write and search
Included
ID 6417 · 2025 · 5 mark(s)
Keshav is the IT Head in a hospital. He needs to manage the records of all the doctors in the hospital. For this, he wants to store the following information of each doctor in a file :
D_ID – An integer to store Doctor ID.
D_Name – A string to store doctor's name.
D_Dept – A string to store the Department of the doctor. (Surgery, Radiology, etc.)
Experience – An integer to store doctor's experience (in years)
For example, a doctor's information may be : [1256, 'R. Gupta', 'Cardiology', 15]
As an applicant for the post of a Programmer, you have to answer the following questions in this context :
(I) Write one difference of storing this data in a binary file over a CSV file.
(II) Assume that the data is stored in a binary file, named DOCTORS.DAT, and each record is stored as a list. Write a function, in Python, to read and display all the records from the file DOCTORS.DAT.
(III) Write a function addDoctor(), in Python, which accepts a doctor's data from the user and writes it in the file DOCTORS.DAT.
File Handling → CSV file read write and search, Binary file operations with pickle
Included
ID 6261 · 2026 · 4 mark(s)
A csv file "States.csv" contains some data about all the states of India. Each record of the file contains the following data :
· Name of the State
· Capital of the State
· Population of the State
· Official Language of the State
For example, a sample record in the file is :
['Andhra Pradesh', 'Amaravati', 52221000, 'Telugu']
Write a Python program which reads the data from this file and appends all those records where population is more than 10000000 into another csv file 'More.csv'.
Note : "States.csv" also contains the Header row. The Header row should NOT be copied to "More.csv".