0% found this document useful (0 votes)
1 views

ComputerScienceXIIf

The document presents a series of questions and answers related to Python programming, specifically focusing on CSV file handling and binary file operations. It includes code snippets and asks for the correct commands or functions to complete the code, along with explanations of file access modes and database queries. The answers are provided for each question, indicating the correct options for completing the code and understanding the concepts discussed.

Uploaded by

psdspace007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

ComputerScienceXIIf

The document presents a series of questions and answers related to Python programming, specifically focusing on CSV file handling and binary file operations. It includes code snippets and asks for the correct commands or functions to complete the code, along with explanations of file access modes and database queries. The answers are provided for each question, indicating the correct options for completing the code and understanding the concepts discussed.

Uploaded by

psdspace007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Class: XII Correct Answer : c) writer(fh)

Subject: COMPUTER SCIENCE iv. Identify the suitable code for blank space in line marked as Statement-4.
Q. No. 1 Rohit, a student of class 12th, is learning CSV File Module in Python. During a) 'ROLL_NO', 'NAME', 'CLASS', 'SECTION'
examination, he has been assigned an incomplete python code (shown below) b) ROLL_NO, NAME, CLASS, SECTION
to create a CSV File 'Student.csv' (content shown below). Help him in c) 'roll_no','name','Class','section'
completing the code which creates the desired CSV File. d) roll_no,name,Class,section c) co.connect()

CSV File Correct Answer : d) roll_no,name,Class,section


1,AKSHAY,XII,A v. Choose the function name that should be used in the blank space of line marked
2,ABHISHEK,XII,A as Statement-5 to create the desired CSV File?
3,ARVIND,XII,A a) dump()
4,RAVI,XII,A b) load()
5,ASHISH,XII,A c) writerows()
d) writerow()
Incomplete Code
import_____ #Statement-1 Correct Answer : c) writerows()
fh = open(_____, _____, newline='') #Statement-2
stuwriter = csv._____ #Statement-3
Q. No. 2 Amritya Seth is a programmer, who has recently been given a task to write a
data = []
header = ['ROLL_NO', 'NAME', 'CLASS', 'SECTION'] python code to perform the following binary file operations with the help of
data.append(header) two user defined functions/modules:
for i in range(5):
roll_no = int(input("Enter Roll Number : ")) a. AddStudents() to create a binary file called STUDENT.DAT
name = input("Enter Name : ") containing student information – roll number, name and marks (out
Class = input("Enter Class : ") of 100) of each student.
section = input("Enter Section : ") b. GetStudents() to display the name and percentage of those students
rec = [_____] #Statement-4 who have a percentage greater than 75. In case there is no student
data.append(rec) having percentage > 75 the function displays an appropriate
stuwriter. _____ (data) #Statement-5
fh.close()
message. The function should also display the average percent.
i. Identify the suitable code for blank space in line marked as Statement-1.
He has succeeded in writing partial code and has missed out certain
a) csv file
statements, so he has left certain queries in comment lines. You as an expert
b) CSV
of Python have to provide the missing statements and other related queries
c) csv
based on the following code of Amritya.
d) Csv
Answer any four questions (out of five) from the below mentioned questions.
Correct Answer : c) csv
ii. Identify the missing code for blank space in line marked as Statement-2? import pickle
a) "School.csv","w" def AddStudents():
b) "Student.csv","w" ____________ #1 statement to open the binary file to
c) "Student.csv","r" write data
d) "School.csv","r" while True:
Rno = int(input("Rno :"))
Correct Answer : b) "Student.csv","w" Name = input("Name : ")
Percent = float(input("Percent :"))
iii. Choose the function name (with argument) that should be used in the blank
L = [Rno, Name, Percent]
space of line marked as Statement-3 ____________ #2 statement to write the list L
a) reader(fh) into the file
b) reader(MyFile) Choice = input("enter more (y/n): ")
c) writer(fh) if Choice in "nN":
d) writer(MyFile) break
F.close()
a. ‘r+’ opens a file for both reading and writing. File object points to its
def GetStudents(): beginning.
Total=0 b. ‘w+’ opens a file for both writing and reading. Adds at the end of the
Countrec=0
existing file if it exists and creates a new one if it does not exist.
Countabove75=0
with open("STUDENT.DAT","rb") as F: c. ‘wb’ opens a file for reading and writing in binary format. Overwrites
while True: the file if it exists and creates a new one if it does not exist.
try: d. ‘a’ opens a file for appending. The file pointer is at the start of the file
____________ #3 statement to read if the file exists.
from the file
Countrec+=1 Correct Answer : a
Total+=R[2] v. Which of the following statements correctly explain the function of seek()
if R[2] > 75: method?
print(R[1], " has percent =
a. tells the current position within the file.
",R[2])
Countabove75+=1 b. determines if you can move the file position or not.
except: c. indicates that the next read or write occurs from that position in a file.
break d. moves the current file position to a given specified position
if Countabove75==0:
print("There is no student who has Correct Answer : d
percentage more than 75")
average=Total/Countrec Q. No. 3 Krrishnav is looking for his dream job but has some restrictions. He loves Delhi
print("average percent of class = ",average) and would take a job there if he is paid over Rs.40,000 a month. He hates
AddStudents()
Chennai and demands at least Rs. 1,00,000 to work there. In any another
GetStudents() location he is willing to work for Rs. 60,000 a month. The following code
i. Which of the following commands is used to open the file “STUDENT.DAT” shows his basic strategy for evaluating a job offer.
for writing only in binary format? (marked as #1 in the Python code)
a. F= open("STUDENT.DAT",'wb') Code:
b. F= open("STUDENT.DAT",'w')
pay= _________
c. F= open("STUDENT.DAT",'wb+') location= _________
d. F= open("STUDENT.DAT",'w+') if location == "Mumbai":
print ("I’ll take it!") #Statement 1
Correct Answer : a. F= open("STUDENT.DAT",'wb') elif location == "Chennai":
ii. Which of the following commands is used to write the list L into the binary file, if pay < 100000:
STUDENT.DAT? (marked as #2 in the Python code) print ("No way") #Statement 2
a. pickle.write(L,f) else:
b. pickle.write(f, L) print("I am willing!") #Statement 3
elif location == "Delhi" and pay > 40000:
c. pickle.dump(L,F)
print("I am happy to join") #Statement 4
d. f=pickle.dump(L) elif pay > 60000:
print("I accept the offer") #Statement 5
Correct Answer : c. pickle.dump(L,F) else:
iii. Which of the following commands is used to read each record from the binary print("No thanks, I can find something
file STUDENT.DAT? (marked as #3 in the Python code) better")#Statement 6
a. R = pickle.load(F)
b. pickle.read(r,f) On the basis of the above code, choose the right statement which will be
c. r= pickle.read(f) executed when different inputs for pay and location are given.
d. pickle.load(r,f) i. Input: location = "Chennai”, pay = 50000
a. Statement 1
Correct Answer : a. R = pickle.load(F) b. Statement 2
iv. Which of the following statement(s) are correct regarding the file access c. Statement 3
modes? d. Statement 4
Correct Answer : ii. Statement 2 d. Library.update(Book)
ii. Input: location = "Surat" ,pay = 50000 Correct Answer: d
a. Statement 2 iii. What will be the output of the following line of code:
b. Statement 4 print(list(Library))
c. Statement 5 a. [‘5’,’Madras Diaries’,’6’,’Malgudi Days’]
d. Statement 6 b. (‘5’,’Madras Diaries’,’6’,’Malgudi Days’)
c. [’Madras Diaries’,’Malgudi Days’]
Correct Answer: d. Statement 6 d. [‘5’,’6’]
iii. Input- location = "Any Other City", pay = 1
Correct Answer: d
a Statement 1 iv. In order to check whether the key 2 is present in the dictionary Book, Ramesh
b. Statement 2 uses the following command:
c. Statement 4 2 in Book
d. Statement 6 He gets the answer ‘True’. Now to check whether the name ‘Madras Diaries’
exists in the dictionary Library, he uses the following command:
Correct Answer: d. Statement 6 ‘Madras Diaries’ in Library
iv. Input location = "Delhi", pay = 500000 But he gets the answer as ‘False’. Select the correct reason for this:
a. Statement 6 a. We cannot use the in function with values. It can be used with keys only.
b. Statement 5 b. We must use the function Library.values() along with the in operator
c. Statement 4 c. We can use the Library.items() function instead of the in operator
d. Statement 3 d. Both b and c above are correct.

Correct Answer: c. Statement 4 Correct Answer: b


v. v. Input- location = "Lucknow", pay = 65000 v. With reference to the above declared dictionaries, predict the output of the
i. Statement 2 following code fragments
ii. Statement 3 Code 1 Code 2
iii. Statement 4 Library=Book Library=Book.copy()
iv. Statement 5 Library.pop(2) Library.pop(2)
print(Library) print(Library)
Correct Answer: d. Statement 5
print(Book) print(Book)
Q. No. 4 Consider the following code and answer the questions that follow:
Book={1:'Thriller', 2:'Mystery', 3:'Crime', 4:'Children a) Code 1 Code 2
Stories'} {1: 'Thriller', 2: {1: 'Thriller', 3:
Library ={'5':'Madras Diaries','6':'Malgudi Days'} 'Mystery', 3: 'Crime', 'Crime', 4: 'Children
i. Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime 4: 'Children Stories'} Stories'}
{1: 'Thriller', 2: {1: 'Thriller', 3:
Thriller’. He has written the following command:
'Mystery', 3: 'Crime', 'Crime', 4: 'Children
Book[‘Crime’]=’Crime Thriller’ 4: 'Children Stories'} Stories'}
But he is not getting the answer. Help him choose the correct command:
a. Book[2]=’Crime Thriller’
b. Book[3]=’Crime Thriller’ b) Code 1 Code 2
{1: 'Thriller', 3:
c. Book[2]=(’Crime Thriller’)
'Crime', 4: 'Children
d. Book[3] =(‘Crime Thriller’) {2:’Mystery’} Stories'}
{1: 'Thriller', 2: {1: 'Thriller', 3:
Correct Answer: b 'Mystery', 3: 'Crime', 'Crime', 4: 'Children
ii. The command to merge the dictionary Book with Library the command would 4: 'Children Stories'} Stories'}
be:
a. d=Book+Library c) Code 1 Code 2
b. print(Book+Library)
c. Book.update(Library)
{1: 'Thriller', 3: {1: 'Thriller', 3:
'Crime', 4: 'Children 'Crime', 4: 'Children Correct Answer:
Stories'} Stories'} a. SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE
{1: 'Thriller', 3: {1: 'Thriller', 2:
STUDENTS.ADMNO=SPORTS.ADMNO AND ADDRESS IS NOT
'Crime', 4: 'Children 'Mystery', 3: 'Crime', 4:
Stories'} 'Children Stories'}
NULL;
ii. Identify the statement to delete a column phone from the table students.
d) Code 1 Code 2 a. ALTER TABLE STUDENTS DROP PHONE;
{1: 'Thriller', 3: {1: 'Thriller', 3:
b. DROP PHONE;
'Crime', 4: 'Children 'Crime', 4: 'Children
Stories'} Stories'} c. UPDATE DROP PHONE;
{1: 'Thriller', 2: {1: 'Thriller', 3: d. DELETE FROM STUDENTS WHERE DROP PHONE;
'Mystery', 3: 'Crime', 'Crime', 4: 'Children
4: 'Children Stories'} Stories'} Correct Answer:
a. ALTER TABLE STUDENTS DROP PHONE;
Correct Answer: c iii. Choose the command to display Name of the students who are studying in class
12 and their corresponding Coach names

Q. No. 5 In a Database, there are two tables with the instances given below: a. SELECT NAME, COACHNAME FROM STUDENTS, SPORTS
WHERE CLASS LIKE “12%” AND STUDENTS.ADMNO
Table: STUDENTS =SPORTS.ADMNO;
ADMNO NAME CLASS SEC RNO ADDRESS PHONE b. SELECT NAME, COACHNAME FROM STUDENTS, SPORTS
WHERE CLASS LIKE “12%” AND STUDENTS.ADMNO=
1211 MEENA 12A D 4 A-26 3245678
SPORTS.ADMNO;
1212 VANI 10A D 1 B-25 5456789 c. SELECT NAME, COACHNAME FROM STUDENTS, SPORTS
1213 MEENA 12B A 1 NULL NULL WHERE CLASS LIKE “12%” AND ADMNO.STUDENTS
1214 KARISH 10B B 3 AB-234 4567890 =ADMNO.SPORTS;
d. SELECT NAME, COACHNAME FROM STUDENTS, SPORTS
Table: SPORTS WHERE CLASS LIKE= “12%” AND STUDENTS.ADMNO
ADMNO GAME COACHNAME GRADE =SPORTS.ADMNO;
1215 CRICKET MR. RAVI A
1213 VOLLEYBALL MR. AMANDEEP B Correct Answer:
1211 VOLLEYBALL MR. GOVARDHAN A a. SELECT NAME, COACHNAME FROM STUDENTS,SPORTS WHERE
CLASS LIKE “12%” AND STUDENTS.ADMNO=SPORTS.ADMNO ;
1212 BASKET BALL MR TEWARI B
iv. which two select queries will give the same output

A. SELECT NAME, GRADE FROM STUDENTS,SPORTS WHERE


i. Choose the command to display name and game of those students whose
ADDRESS IS NULL AND STUDENTS.ADMNO =SPORTS.ADMNO ;
address is available in students’ table.
B. SELECT NAME, GRADE FROM STUDENTS,SPORTS WHERE
ADDRESS IS NOT NULL AND STUDENTS.ADMNO
a. SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE
=SPORTS.ADMNO ;
STUDENTS.ADMNO=SPORTS.ADMNO AND ADDRESS IS NOT
C SELECT NAME, GRADE FROM STUDENTS,SPORTS WHERE
NULL;
ADDRESS IS NULL OR STUDENTS.ADMNO=SPORTS.ADMNO ;
b. SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE
D. SELECT ST.NAME, SP.GRADE FROM STUDENTS ST,SPORTS SP
STUDENTS.ADMNO=SPORTS.ADMNO AND ADDRESS IS
WHERE ADDRESS IS NULL AND ST.ADMNO=SP.ADMNO ;
NULL;
a. A AND B
c. SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE
b. B AND C
STUDENTS.ADMNO=SPORTS.ADMNO, ADDRESS IS NULL;
c. A AND D
d. SELECT NAME, GAME FROM STUDENTS, SPORTS WHERE
d. C AND D
STUDENTS.ADMNO=SPORTS.ADMNO NOT ADDRESS IS
NULL;
Correct Answer: c. A AND D
v. Choose the command to count the number of students who play volleyball
Correct Answer: b. Star topology
a. SELECT COUNT(*) FROM STUDENTS,SPORTS WHERE ii. The company wants internet accessibility in all the blocks. The suitable and
GAME=”VOLLEYBALL” AND STUDENTS.ADMNO=SPORTS.ADMNO cost-effective technology for that would be:
; a. Satellite
b. SELECT COUNT(GAME) FROM STUDENTS,SPORTS WHERE b. Lease line
GAME=”VOLLEYBALL” AND STUDENTS.ADMNO=SPORTS.ADMNO c. Telephone line
; d. Broadband
c. SELECT COUNT(*) FROM STUDENTS,SPORTS WHERE
GAME=”VOLLEYBALL” ; Correct Answer: d. Broadband
d. SELECT COUNT(*) FROM STUDENTS,SPORTS WHERE
SPORTS=”VOLLEYBALL” AND iii. Which one of the following devices will you suggest for connecting all the
STUDENTS.ADMNO=SPORTS.ADMNO computers with in each of their blocks?
a. Switch/Hub
Correct Answer : b. Modem
a. SELECT COUNT(*) FROM STUDENTS,SPORTS WHERE c. Telephone
GAME=”VOLLEYBALL” AND STUDENTS.ADMNO=SPORTS.ADMNO d. Repeater
;
Correct Answer: a. Switch/Hub
Q. No. 6 A company ABC Enterprises has four blocks of buildings as shown: iv. The company is planning to link its head office situated in New Delhi with the
offices in hilly areas. Suggest a way to connect it economically:
B1 B4 a. Micro waves
b. Coaxial cable
c. Fibre optic
d. Radio waves
B2 B3
Correct Answer: d. Radio waves
v. Suggest the most appropriate location of the server, to get the best connectivity
Center to center distance between various blocks for maximum number of computers.
B3 TO B1 50 M a. BLOCK B2
B1 TO B2 60 M b. BLOCK B1
B2 TO B4 25 M c. BLOCK B4
B4 TO B3 170 M d. BLOCK B3
B3 TO B2 125 M
Correct Answer: b. BLOCK B1
B1 TO B4 90 M
Q. No. 7 Millions of computer science students have taken a course on algorithms and
Number of computers in each block : data structures, typically the second course after the initial one introducing
B1 150 M programming. One of the basic data structures in such a course is the stack. The
B2 15 M stack has a special place in the emergence of computing as a science, as argued
B3 15 M by Michael Mahoney, the pioneer of the history of the theory of computing.
B4 25 M The Stack can be used in many computer applications, few are given below:
Computers in each block are networked but blocks are not networked. The a) In recursive function
company has now decided to connect the blocks also. b) When function is called.
c) Expression conversion such as – Infix to Postfix, Infix to Prefix, Postfix
i. Suggest the most appropriate topology for the connections between the blocks. to Infix, Prefix to Infix.
a. Ring topology In Stack, insertion operation is known as Push whereas deletion operation is
b. Star topology known as Pop.
c. Mesh topology
d. Bus topology Code – 1
def push(Country,N): Correct Answer : c. len(country)==0
Country._________(len(Country),N)) #Statement 1 iv. Fill the statement 4, to delete an element from the stack.
a. pop(1)
#Function Calling
Country=[]
b. pop()
C=['Indian', 'USA', 'UK', 'Canada', 'Sri Lanka'] c. del country[1]
for i in range(0,len(C),________): #Statement 2 d. Country.delete(1)
push(Country,C[i])
print(Country) Correct Answer: b. pop()

Required Output: v. Fill the statement 5, to call the pop function.


['Indian', 'UK', 'Sri Lanka'] a. pop(C)
b. pop(Country)
Code - 2 c. call pop(Country)
def pop(Country): d. def pop(Country)
if ______________: #Statement 3
return "Under flow" Correct Answer: b. pop(Country)
else:
return Country.________() #Statement 4
Q. No. 8 Arun, during Practical Examination of Computer Science, has been assigned
#Function Calling an incomplete search() function to search in a pickled file student.dat. The File
for i in range(len(Country)+1): student.dat is created by his Teacher and the following information is known
print(_______________) #Statement 5 about the file.
• File contains details of students in [roll_no,name,marks] format.
• File contains details of 10 students (i.e. from roll_no 1 to 10) and
Required Output: separate list of each student is written in the binary file using dump().
Sri Lanka Arun has been assigned the task to complete the code and print details of roll
UK number 1.
India
Under flow def search():
f = open("student.dat",____)
Fill the above statement based on given questions: #Statement-1
i. Identify the suitable code for the blank of statement 1. ____: #Statement-2
a. .append() while True:
b. .insert() rec = pickle.____
#Statement-3
c. .extend()
if(____): #Statement-4
d. .append(len(Country),N) print(rec)
except:
Correct Answer : b. .insert() pass
ii. Fill the statement 2, to insert the alternate element from Country list. ____ #Statement-5
a. 3
b. 0 i. In which mode Arun should open the file in Statement-1?
c. -1 a) r
d. 2 b) r+
c) rb
Correct Answer : d. 2 d) wb
iii. Fill the statement 3, to check the stack is empty.
a. Country=[] Correct Answer: c) rb
b. Country.isEmpty() ii. Identify the suitable code to be used at blank space in line marked as Statement-
c. len(country)==0 2
d. No of the above a) if(rec[0]==1)
b) for i in range(10) try:
c) try with open('books.csv','r') as csvf:
d) pass cr=______ #Statement-4
for r in cr:
if ______: #Statement-5
Correct Answer: c) try print(r)
iii. Identify the function (with argument), to be used at blank space in line marked except:
as Statement-3. print('File Not Found')
a) load()
b) load(student.dat)
c) load(f) CSVOpen()
d) load(fin) CSVRead()

Correct Answer: c) load(f) You as an expert of Python have to provide the missing statements and other
iv. What will be the suitable code for blank space in line marked as Statement-4. related queries based on the following code of Radha.
a) rec[0]==2 Answer any four questions (out of five) from the below mentioned questions.
b) rec[1]==2 i. Choose the appropriate mode in which the file is to be opened in append mode
c) rec[2]==2 (Statement 1)
d) rec[0]==1 a. w+
b. ab
Correct Answer: d) rec[0]==1 c. r+
v. Which statement Arun should use at blank space in line marked as Statement- d. a
4 to close the file.
a) file.close() Correct Answer: d. a
b) close(file) ii. Which statement will be used to create a csv writer object in Statement 2.
c) f.close() a. csv.writer(csvf)
d) close() b. csv.writer(csvf)
c. csvf.writer()
Correct Answer: c) f.close() d. cs.writer(csvf)

Q. No. 9 Radha Shah is a programmer, who has recently been given a task to write a Correct Answer: b. csv.writer(csvf)
python code to perform the following CSV file operations with the help of two iii. Choose the correct option for Statement 3 to write the names of the column
user defined functions/modules: headings in the CSV file, BOOKS.CSV.
a. cw.writerow('Title','Author','Price')
a. CSVOpen() : to create a CSV file called BOOKS.CSV in append mode b. cw.writerow(['Title','Author','Price'])
containing information of books – Title, Author and Price. c. cw.writerows('Title','Author','Price')
b. CSVRead() : to display the records from the CSV file called d. cw.writerows(['Title','Author','Price'])
BOOKS.CSV where the field title starts with 'R'.
She has succeeded in writing partial code and has missed out certain statements, Correct Answer: b. cw.writerow(['Title','Author','Price'])
so she has left certain queries in comment lines. iv. Which statement will be used to read a csv file in Statement 4.
a. cs.read(csvf)
import csv b. csv.reader(csvf)
def CSVOpen(): c. csvf.read()
with open('books.csv','______',newline='') as csvf: d. csvf.reader(cs)
#Statement-1
cw=______ #Statement-2 Correct Answer: b. csv.reader(csvf)
______ #Statement-3
cw.writerow(['Rapunzel','Jack',300])
v. Fill in the appropriate statement to check the field Title starting with ‘R’ for
cw.writerow(['Barbie','Doll',900]) Statement 5 in the above program.
cw.writerow(['Johnny','Jane',280]) a. r[0][0]=='R'
b. r[1][0]=='R'
def CSVRead(): c. r[0][1]=='R'
d. d) r[1][1]=='R' d. not Empty

Correct Answer: a. r[0][0]=='R' Correct Answer : a isEmpty( )


v. Specify the range to print all queue elements in statement-5?
Q. No. 10 Ankita is writing a program to perform some operations in Queue. She has a. print(queue=[0:len=(queue)])
created three Insert_in_Queue(Student), Delete_from_Queue(Student) and b. print(queue[0:len(queue)])
Print_Queue(Student) methods/functions in Python to add a new Student name, c. print(queue[[0:len]])
delete a Student name and print list of student from a queue, considering them d. print(queue[0=len(queue)])
to act as insert, delete and print operations of the Queue data structure. She is
not getting the desired result. Help her to get the desired result from the given Correct Answer : b. print(queue[0:len(queue)])
python code.
def Insert_in_Queue(queue): Q. No. 11 Priyank is a software developer with a reputed firm. He has been given the task
a=input("enter student name: ") to computerise the operations for which he is developing a form which will
queue.____________ # Statement-1 accept customer data as follows:
def Delete_from_Queue (queue): i. The DATA TO BE ENTERED IS :
if (____________): # Statement-2 a. Name
print("Queue empty") b. Age
else: c. Items bought( all the items that the customer bought)
print("Deleted element is: ",queue[0]) d. Bill amount
del queue[___] #Statement-3
Correct Answer :
def Print_Queue(queue): i. Choose the most appropriate data type to store the above information
if not ________: #Statement-4
in the given sequence.
print(queue[__:___ ]) # Statement-5
a. string, tuple, float, integer
i. What Ankita should write to complete the Statement-1 to store the student
b. string, integer, dictionary, float
name?
c. string, integer, integer, float
a. queue.append(a)
d. string, integer, list, float
b. queue=append(a)
c. queue.append=a Correct Answer :
d. append(a).queue
ii. Now the data of each customer needs to be organised such that the
customer can be identified by name followed by the age, item list and bill
Correct Answer: a queue.append(a)
amount. Choose the appropriate data type that will help Priyank accomplish
ii. Fill in the blank in Statement-2 to check whether the queue is empty or not?
this task.
a. isEmpty(Queue) a. List
b. isEmpty(q)
b. Dictionary
c. Queue.isEmpty c. Nested Dictionary
d. Empty.Queue
d. Tuple
Correct Answer: a isEmpty(Queue) Correct Answer :
iii. iii. Fill in the blank in Statement-3 with index number. iii. Which of the following is the correct way of storing information of
a. delete(0) customers named ‘Paritosh’ and ‘Bhavesh’ with respect to the option chosen
b. del queue[0] above?
c. delete.queue(0)
a. a.customers= {‘Paritosh’:24,[‘Printed Paper’, ‘ Penstand’], 3409,
d. queue.delete[0] ‘Bhavesh’: 45,[‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘Gift Wrap’],
8099.99 }
Correct Answer: b) del queue[0] b. customers={‘Paritosh’:[24,[‘Printed Paper’, ‘ Penstand’], 3409],
iv. Select the correct option to complete the statement at statement-4. ‘Bhavesh’: [45,[‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘Gift Wrap’],
a. isEmpty( ) 8099.99] }
b. Empty( )
c. len( ) = 0
c. c.customers= [‘Paritosh’:24,‘Printed Paper’, ‘ Penstand’, 3409, b. Line.split()
‘Bhavesh’: 45,‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘Gift Wrap’, c. line.split()
8099.99 ] d. split.word()
d. customers=(‘Paritosh’:24,[‘Printed Paper’, ‘ Penstand’], 3409,
‘Bhavesh’: 45,[‘A4 Rim’,’Printer Cartridge’, ‘Pen Carton’, ‘Gift Wrap’], Correct Answer: c. line.split()
8099.99 ) iv. Fill in the blank in statement-4, which display the word having lesser than 4
characters.
Correct Answer : a. len(c) ==4
iv. In order to calculate the total bill amount for 15 customers, Priyank b. len(c)<4
Statement 1. must use a variable of the type float to store the sum. c. len ( )= =3
Statement 2. may use a loop to iterate over the values d. len ( )==3
a. Both statements are correct.
b. Statement 1 is correct, but statemnt 2 is not. Correct Answer: b. len(c)<4
c. Both statements ar incorrect. v. Fill in the blank in Statement-5 to close the file.
d. Statement 1 is incorrect but statement 2 is correct. a. file.close()
b. File.Close()
Correct Answer : c. Close()
d. end()
Q. No. 12 Your teacher has given you a method/function FilterWords() in python which
read lines from a text file NewsLetter.TXT, and display those words, which are Correct Answer: a. file.close()
lesser than 4 characters. Your teachers intentionally kept few blanks in between
the code and asked you to fill the blanks so that the code will run to find desired
result. Do the needful with the following python code.

def FilterWords():
c=0
file=open('NewsLetter.TXT', '_____') #Statement-1
line = file._____ #Statement-2
word = _____ #Statement-3
for c in word:
if _____: #Statement-4
print(c)
_________ #Statement-5

FilterWords()
i. Write mode of opening the file in statement-1?
a. a
b. ab
c. w
d. r

Correct Answer: d. r
ii. Fill in the blank in statement-2 to read the data from the file.
a. File.Read()
b. file.read()
c. read.lines( )
d. readlines( )

Correct Answer: b. file.read()


iii. Fill in the blank in statement-3 to read data word by word.
a. Line.Split()

You might also like