Please refer to the MCQ Questions for Class 11 Computer Science Chapter 3 Data Handling with Answers. The following Data Handling Class 11 Computer Science MCQ Questions have been designed based on the latest syllabus and examination pattern for Class 11. Our experts have designed MCQ Questions for Class 11 Computer Science with Answers for all chapters in your NCERT Class 11 Computer Science book.
Data Handling Class 11 MCQ Questions with Answers
See below Data Handling Class 11 Computer Science MCQ Questions, solve the questions and compare your answers with the solutions provided below.
Question. To open a file c:\scores.csv for reading, we use _______ command.
(a) infile = open(“c:\scores.csv”, “r”)
(b) infile = open(“c:\\scores.csv”, “r”)
(c) infile = open(file = “c:\scores.csv”, “r”)
(d) infile = open(file = “c:\\scores.csv”, “r”)
Answer
B
Question. The csv files are Binary Files:
(a) True
(b) False
Answer
B
Question. Which of the following statement(s) are true for csv files?
(a) When you open a file for reading, if the file does not exist, an error occurs
(b) When you open a file for writing, if the file does not exist, a new file is created
(c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file
(d) All the above
Answer
D
Question. Choose the possible output from the following code:
import csv def addFile(Name,Phno):
f=open(“Diary.csv”,”a”,newline=”)
newFileWriter = csv.writer(f)
newFileWriter.writerow([Name,Phno])
f.close()
def readFile():
with open(“Diary.csv”,’r’) as f:
filereader = csv.reader(f)
for row in filereader:
print (row[0],row[1])
f.close()
addFile(“SOMU”,”9867564534″)
addFile(“KRISH”,”9678564534″)
readFile()
(a) KRISH 9678564534 SOMU 9867564534
(b) SOMU 9867564534 KRISH 9678564534
(c) somu 9867564534 krish 9678564534
(d) ‘SOMU’ 9867564534 ‘KRISH’ 9678564534
Answer
B
Question. The full form of CSV is
(a) Comma Separated Values
(b) Comma Separated Value
(c) Comma Separated Variables
(d) Comma Separate Values
Answer
A
Question.The CSV files only take comma as delimiter.
(a) True
(b) False
Answer
B
Question. EOL character used in windows operating system in CSV file is
(a) \r
(b) \n
(c) \r\n
(d) \0
Answer
C
Question. The CSV files are ____ files.
(a) Text
(b) Binary
(c) Data
(d) Python
Answer
A
Question. The CSV files are popular because they are
(a) capable of storing large amount of data
(b) easier to create
(c) preferred export and import format for databases and spread sheets
(d) All the above
Answer
D
Question. To read the entire content of the CSV file as a nested list from a file object infile, we use __________ command.
(a) infile.read()
(b) infile.reader()
(c) csv.reader(infile)
(d) infile.readlines()
Answer
C
Question. The separator character of csv files is called delimiter.
(a) True
(b) False
Answer
A
Question. A CSV file is open in the same way as text file.
(a) True
(b) False
Answer
A
Question. Which of the following is not a valid mode to open CSV file?
(a) a
(b) w
(c) ab
(d) r
Answer
C
Question. The file mode to open a CSV file for appending as well as reading is _____.
(a) a+
(b) w+
(c) r+
(d) All the above.
Answer
A
Question. The file mode to open a CSV file for reading as well as writing is _____.
(a) a+
(b) w+
(c) r+
(d) All the above.
Answer
A
Question. The default delimiter character of CSV file is____.
(a) : (colon)
(b) \t (tab)
(c) , (comma)
(d) ; (semi-colon)
Answer
C
Case Based Questions :
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
Incomplete Code
______ csv #Statement 1
def Create_CSV():
fw=open(“Customer.csv”,”w”)
_______=csv.writer(fw) #Statement 2
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 3
fw.close()
def Display_CSV():
fr=open(“__________”,”r”) #Statement 4
Cusreader=csv.reader(fr)
i=0
for ____ in Cusreader: #Statement 5
if i%2==0:
print(rec[0],’\t’,rec[1],’\t’,rec[2],’\t’,rec[3])
else:
pass
i+=1
fr.close()
Create_CSV()
Display_CSV()
Question. Identify the argument name for the blank space in line marked as Statement-3?
(a) Row
(b) Rec
(c) row
(d) rec
Answer
B
Question. Identify the missing file name for the blank space in line marked as Statement-4?
(a) Customer
(b) Customer.csv
(c) Customer.txt
(d) Customer.dat
Answer
B
Question. Identify suitable code for the blank space in line marked as Statement-1.
(a) include
(b) add
(c) Import
(d) import
Answer
D
Question. Identify the missing code for the blank space in line marked as Statement-2.
(a) Customer
(b) reader
(c) Cuswriter
(d) writer
Answer
C
Question. Identify the object name for the blank space in line marked as Statement-5?
(a) i
(b) Rec
(c) row
(d) rec
Answer
D
Mohan has written following program to create a CSV file “File_extent.csv” which will contain file types and file extensions for some records. As a programmer, help him to successfully execute the given task:
import ______ # Statement 1
def adddata(filetype,extension): # To write /add data into the file
f=open(______,_____,newline=”) # Statement 2
newFileWriter = csv.writer(f)
newFileWriter.writerow([filetype,extension])
f.close()
#Csv file reading code
def readdata(filename): # To read data
with open(filename,’r’) as f:
filereader = csv.______(f) # Statement 3
for row in filereader:
print (row[0],row[1])
f._______ # Statement 4
adddata(“Notepad”,”txt”)
adddata(“Word”,”docx”)
adddata(“Excel”,”xlsx”)
adddata(“PowerPoint”,”pptx”)
readdata(“________”) #Statement 5
Question. Choose the correct option for Statement 3 to read the data from a csv file.
(a) read()
(b) readline()
(c) load()
(d) reader
Answer
D
Question. Choose the correct option for Statement 4 to close the file.
(a) end()
(b) close()
(c) close
(d) from
Answer
B
Question. Choose the correct option for Statement 5 to send the file name as parameter.
(a) “File_extent.csv”
(b) File_extent.csv
(c) File_extent
(d) .csv
Answer
B
Question. Identify the module he should import for Statement 1.
(a) math
(b) csv
(c) pickle
(d) random
Answer
B
Question. Choose the correct option for Statement 2 to open file name and mode. (Suresh should open the file to add data into the file)
(a) “File_extent.csv”,”r”
(b) “File_extent.csv”,”w”
(c) “File_extent.csv”,”a”
(d) “File_extent.csv”,”w+”
Answer
C
Ashok Kumar of class 12 is writing a program to create a CSV file “empdata.csv” with empid, name & mobile number. Also to search a particular empid and display its record details. He has written the following code. As a programmer, help him to successfully execute the given task.
import ______ #Line1
fields=[’empid’,’name’,’mobile_no’]
rows=[[‘101′,’Rohit’,’8982345659′],[‘102′,’Shaurya’,’8974564589′],[‘103′,’Deep’,’8753695421′],[‘104’,’P
rerna’,’9889984567′],[‘105′,’Lakshya’,’7698459876′]]
filename=”empdata.csv”
f=open(filename,’w’,newline=”)
csv_w=csv.writer(f)
csv_w._________ #Line2
for row in rows:
csv_w.______ #Line3
f.close()
f=open(filename,’r’)
csv_r=________ #Line4
ans=’y’
while ans==’y’:
found=False
emplid=input(“Enter employee id to search=”)
for row in csv_r:
if len(row)!=0:
if _______==emplid: #Line5
print(“Name : “,row[1])
print(“Mobile No : “,row[2])
found=True
break
if not found:
print(“Employee id not found”)
ans=input(“Do you want to search more? (y)”)
Question. Choose a code to write the row from rows list in Line3.
(a) writerows(row)
(b) writerow(row)
(c ) writerow(rows)
(d) write_row(row)
Answer
B
Question. Choose a code for line 4 to read the data from a csv file.
(a) csv.reader(f)
(b) csv.read(f)
(d) pickle.load(f)
(e) f.read()
Answer
A
Question. Choose the correct variable (list value) to check “emplid” in Line5.
(a) Row[0]
(b) Rec[0]
(c) row[0]
(d) rec[0]
Answer
C
Question. Choose the module he should import in Line 1.
(a) math
(b) pickle
(c) csv
(d) random
Answer
C
Question. Choose a code to write the fields (column heading) from fields list in Line2.
(a) writerows(fields)
(b) writerow(field)
(c) writerow(fields)
(d) writerows(fields)
Answer
C
Sumit is making a software on “Countries and their Capitals” in which various records are to be stored/retrieved in “CAPITAL.CSV” data file. It consists of few records of Countries and their Capitals. He has written the following code in python. As a programmer, you have to help him to successfully execute the program.
import csv
# Fn. to add a new record in CSV file
def _________(Country,Capital): # Statement-1
f=open(“CAPITAL.CSV”,”__”) # Statement-2
fwriter=csv.writer(f)
fwriter.writerow([_____]) # Statement-3
f.close()
def ShowRec(): # Fn. to display all records from CSV file
with open(“CAPITAL.CSV”,”r”) as NF:
NewReader=csv._____ (NF) # Statement-4
for rec in NewReader:
if len(rec)!=0:
print(rec[0],rec[1])
AddNewRec(“INDIA”,”NEW DELHI”)
AddNewRec(“CHINA”,”BEIJING”)
ShowRec() # Statement-5
Question. Identify the correct variables in Statement-3 to store data to the file.
(a) country,capital
(b) Country,Capital
(c) Coun,Cap
(d) [Country,Capital]
Answer
B
Question. Choose the correct option for Statement-4 to read the data from a csv file.
(a) Reader()
(b) reader()
(c) read
(d) reader
Answer
D
Question. Choose the output which will come after executing Statement-5.
(a) ‘INDIA NEW DELHI’ ‘CHINA BEIJING’
(b) ‘INDIA’ ‘NEW DELHI’ ‘CHINA’ ‘BEIJING’
(c) INDIA NEW DELHI CHINA BEIJING
(d) All the above
Answer
C
Question. Choose the Name of the function in Statement-1.
(a) AddNewRec
(b) Addnew
(c) Addrec
(d) AddNewRec()
Answer
A
Question. Choose the file mode to be passed to add new records in Statement-2.
(a) w
(b) r
(c) w+
(d) a
Answer
D