Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
5.0k views
in Computer by (15.9k points)
edited by

Radha Shah is a programmer, who has recently been given a task to write a python code to perform the following CSV file operations with the help of two user defined functions/modules: 

a. CSVOpen() : to create a CSV file called BOOKS.CSV in append mode containing information of books – Title, Author and Price. 

b. CSVRead() : to display the records from the CSV file called BOOKS.CSV where the field title starts with 'R'. She has succeeded in writing partial code and has missed out certain statements, so she has left certain queries in comment lines. 

import csv 

def CSVOpen(): 

with open('books.csv','______',newline='') 

as csvf: 

#Statement-1 

cw=______     #Statement-2

 ______    #Statement-3 

cw.writerow(['Rapunzel','Jack',300]) 

cw.writerow(['Barbie','Doll',900]) 

cw.writerow(['Johnny','Jane',280]) 

def CSVRead():

try: 

with open('books.csv','r') as csvf: 

cr=______    #Statement-4 

for r in cr: 

if ______:     #Statement-5 print(r) except: 

print('File Not Found') 

CSVOpen() 

CSVRead()

You as an expert of Python have to provide the missing statements and other related queries based on the following code of Radha. Answer from the below mentioned questions.

I. Choose the appropriate mode in which the file is to be opened in append mode (Statement 1) 

a. w+ 

b. ab 

c. r+ 

d. a

II. Which statement will be used to create a csv writer object in Statement 2. 

a. csv.writer(csvf) 

b. csv.writer(csvf) 

c. csvf.writer() 

d. cs.writer(csvf)

III. Choose the correct option for Statement 3 to write the names of the column headings in the CSV file, BOOKS.CSV. 

a. cw.writerow('Title','Author','Price') 

b. cw.writerow(['Title','Author','Price']) 

c. cw.writerows('Title','Author','Price') 

d. cw.writerows(['Title','Author','Price'])

IV. Which statement will be used to read a csv file in Statement 4. 

a. cs.read(csvf) 

b. csv.reader(csvf) 

c. csvf.read() 

d. csvf.reader(cs)

V. Fill in the appropriate statement to check the field Title starting with ‘R’ for Statement 5 in the above program. 

a. r[0][0]=='R' 

b. r[1][0]=='R' 

c. r[0][1]=='R'

d. d) r[1][1]=='R'

Please log in or register to answer this question.

1 Answer

+1 vote
by (15.3k points)

I. Correct Answer: d. a

II. Correct Answer: b. csv.writer(csvf)

III. Correct Answer: b. cw.writerow(['Title','Author','Price'])

IV. Correct Answer: b. csv.reader(csvf)

V. Correct Answer: a. r[0][0]=='R'

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...