0% found this document useful (0 votes)
50 views4 pages

CSV File Handling Assignment (2024-25)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

CSV File Handling Assignment (2024-25)

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

BHATNAGAR INTERNATIONAL SCHOOL, PASCHIM VIHAR

CLASS XII COMPUTER SCIENCE


ASSIGNMENT
FILE HANDLING (CSV FILES)

1. Create a CSV file “users.csv” by entering user-id and password, and write code for the following:
• read and search the password for given user-id.
• Update the password based on given user-id
• Delete the user record based on the user-id
2. What is the difference between writerow() and writerows() function?
3. The character that separates values in csv files is called the ………
a) delimit b) delimiter c) delimited d) delimits
4. The default delimiter of csv file is ……………
a) comma b) colon c) semicolon d) hyphen
5. The file mode to open a csv file for reading as well writing is ………
a) r b) rw c) r+ d) rb
6. To specify a different delimiter while writing into csv file, ……. argument is used with csv.writer().
a) delimit b) delimiter c) delimited d) delimits
7. To cancel the EOL translation in csv file while writing the data ………… argument is used with open().
a) newline b) next c) open d) EOL
8. CSV stands for …….
a) Cursor Separated Variables b) Comma Separated Values c) Cursor Separated Values d) Cursor
Separated Version
9. Which module is used for working with CSV files in Python?
a) random b) statistics c) csv d) math
10. Deepesh works as a programmer with Delta Technologies. He has been assigned the job of generating the salary of all
employees using the file “employee.csv”. He has written a program to read the CSV file “employee.csv” which will
contain details of all the employees. As a programmer, help him to successfully complete the following code.
import______ # Line 1
def readCsvEmp( ): # to read data from the CSV file
with ______('employees.csv', newline='') as f: # Line 2
reader = csv.______ (f) # Line 3
data_list = ______(reader) # Line 4
______ (data_list) # Line 5

11. Puneeta is storing the data of her gift store in a csv file named gift.csv which will
store Gift_code and Gift_name of items of her gift store. She has written the
following code .Complete the folloeing code
import ___________ # Line 1
def writeFile(Gift_code,Gift_name):
F=open(“gift.csv”,‟___‟) #Line 2
FW=csv.________(F) #Line 3
FW.writerow([Gift_code,Gift_name)
F.close()
#CSV file for reading
def readFile():
with ________(„gift.csv‟,‟r‟) as newF #Line 4
FR=csv.reader(newF)
for row in FR:
if row[0]==101:
print(row)
newF.close()
writeFile(101,”Photoframe”)
writeFile(102,”Soft Toys”)
writeFile(103,”Flower Pot”)
readFile()

9. Sonal, a student of class 12th, is learning CSV File Module in Python. During
examination, she has been assigned an incomplete python code (shown below) to create a CSV file
'Customer.csv' (content shown below). Help her in completing the code which creates the desired
CSV file.
Cus_No Name Address Ph_No
11 Rohit Mumbai 8567843243
22 Sonal New Delhi 9645342345
import _______
#Statement 1
def Create_CSV():
fw=open("Customer.csv" , ______, newline='')
#Statement 2
______=csv.writer(fw)
#Statement 3
Cuswriter.writerow(["Cus_No","Name","Address","Ph_No"])
n=int(input("Enter total number of Customer"))
for i in range(n):
Cusno=int(input("Enter Customer no."))
Name=input("Enter Name")
Add=input("Enter Address")
Ph_No=int(input("Enter Phone No."))
Rec=[Cusno,Name,Add,Ph_No]
Cuswriter.writerow(____) #Statement 4
fw.close()
def Display_CSV():
fr=open("__________","r") #Statement 5
Cusreader=csv.reader(fr)
for ____ in Cusreader: #Statement 6
print(rec[0], rec[1], rec[2], rec[3])
fr.close()
Create_CSV()
Display_CSV()

12. (V.Imp—CBSE Sample Paper)


13. Vedansh is a Python programmer working in a school. For the Annual Sports Event, he has created a csv file named
Result.csv, to store the results of students in different sports events. The structure of
Result.csv is :
[St_Id, St_Name, Game_Name, Result]
Where
St_Id is Student ID (integer)
ST_name is Student Name (string)
Game_Name is name of game in which student is participating(string)
Result is result of the game whose value can be either 'Won', 'Lost'
or 'Tie'
For efficiently maintaining data of the event, Vedansh wants to write the following user defined functions:
Accept() – to accept a record from the user and add it to the file
Result.csv. The column headings should also be added on top of the csv file.
wonCount() – to count the number of students who have won any event.
As a Python expert, help him complete the task.

14.

15. 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 from ‘furdata.csv’, whose price is more than 10000.

16. Observe the following code and fill the blanks


import csv
with _________ as f: #statement1
r = csv.______(f) #statement2
for row in ______: #statement3
print(_____) #statement

17. Legend sports wanted to store the number of prizes for each sport as a SPORTS.CSV file.As a programmer help them to complete
the task successfully.
import _______________ #Line 1
fh=___________________ # Line 2
swriter = ______________(fh) #Line 3
ans=‟y‟
i=1
while ans==‟y‟:
print(“Record”,i)
sport=input(“Sport name”)
prizes=int(input(“Enter prizes won”))
__________ # Line 4
i=i+1
ans=input(“Want to enter records”)
fh._________________ #Line 5
18. Krishna of class 12 is writing a program to read the details of Sports performance and store in the csv file “Sports.csv”
delimited with a tab character. As a programmer, help him to achieve the task.
import ___________ # Line 1
f = open(“Sports.csv”,”a”)
wobj = csv.______________ (f, delimiter = “\t‟) # Line 2
wobj.writerow( [“Sport‟, “Competitions‟, “Prizes Won‟] )
ans = “y‟
i=1
while ans == “y‟:
print(“Record :”, i)
sport = input(“Sport Name :”)
comp = int(input(“No. of competitions participated :”))
prize = int(input(“Prizes won:”))
record = ____________________ # Line 3
wobj.______________ (rec) # Line 4
i += 1
ans = input(“Do u want to continue ? (y/n) :”)
f.___________ # Line 5

You might also like