Page 39 - PYTHON-12
P. 39
6. What will be the output of the given code? (1)
dictt = {'a': 1, 'b': 2, 'c': 3}
keys = list(dictt.keys())
print(dictt.get(keys[0]))
(a) 1 (b) a
(c) None (d) Error
7. Predict the output of the following code. (1)
try:
print("Trying to open file")
file = open("non_existent_file.txt")
except FileNotFoundError as e:
print("File not found error")
finally:
print("Execution finished")
(a) Trying to open file
File not found error
(b) Trying to open file
File not found error
Execution finished
(c) Execution finished
(d) Error
8. What is the function of index() method in a list? (1)
(a) To find the total number of elements in the list
(b) To find the position of the first occurrence of a specified element
(c) To check if an element is present in the list
(d) To remove an element from a given position
9. Which of the following best describes the relationship between primary and foreign keys in a database? (1)
(a) A primary key in one table must always correspond to a primary key in another table.
(b) A foreign key in one table references a primary key in the same table only.
(c) A foreign key in one table establishes a link to a primary key in another table to enforce referential
integrity.
(d) A primary key is required to reference multiple foreign keys in different tables simultaneously.
10. What will be the missing statement to check if the file cursor is at the end of the file? (1)
fileobj = open("sample.txt", "r")
while True:
line = fileobj.readline()
if not line:
____________________
break
fileobj.close()
(a) fileobj.seek(0) (b) fileobj.close()
(c) print("End of file reached") (d) fileobj.tell()
A.2 Computer Science–XII