Arun, during Practical Examination of Computer Science, has been assigned an incomplete search() function to search in a pickled file student.dat. The File student.dat is created by his Teacher and the following information is known 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 separate list of each student is written in the binary file using dump().
Arun has been assigned the task to complete the code and print details of roll number 1.
def search():
f = open("student.dat",____) #Statement-1
____: #Statement-2
while True: rec = pickle.____ #Statement-3
if(____): #Statement-4
print(rec)
except:
pass ____ #Statement-5
I. In which mode Arun should open the file in Statement-1?
a) r
b) r+
c) rb
d) wb
II. Identify the suitable code to be used at blank space in line marked as Statement2
a) if(rec[0]==1)
b) for i in range(10)
c) try
d) pass
III. Identify the function (with argument), to be used at blank space in line marked as Statement-3.
a) load()
b) load(student.dat)
c) load(f)
d) load(fin)
VI. What will be the suitable code for blank space in line marked as Statement-4.
a) rec[0]==2
b) rec[1]==2
c) rec[2]==2
d) rec[0]==1
V. Which statement Arun should use at blank space in line marked as Statement4 to close the file.
a) file.close()
b) close(file)
c) f.close()
d) close()