6. Find the output :
class A:
def __init__(self):
self.__x = 1
class B(A):
def display(self):
print(self.__x)
def main():
obj = B()
obj.display()
main()
a. 1
b. 0
c. None
d. Error
View Answer
Ans. d
Explanation : Indentation Error
7. Find the output :
a = 8.3
b = 2
print(a//b)
a. 4.15
b. 4
c. 4.1
d. 4.0
View Answer
Ans. d
Explanation : ‘/’ would have given 4.15 as the answer. However, ‘//’ operator performs floor division.
8. Find the output :
values = ["823", "863"]
num = values[0][0:]
for row in range(0,len(values)):
for column in range(0, len(values[row])):
if num > values[row][column:]:
num = values[row][column:]
print(num)
a. 2
b. 3
c. 23
d. 823
View Answer
Ans. c
Explanation : Loop runs for
row = 0 col = 0
row = 0 col = 1
row = 0 col = 2
row = 1 col = 0
row = 1 col = 1
row = 1 col = 2
So, values[1][2] = 23
9. Find the output :
def function(string,list1):
#line1
while(num!=len(string)):
if len(string)%2==0 or (string[num] in ('a','e','i','o','u')):
list1.append(string[num])
#line2
#line3
break
return list1
print(function("Epoch",[]))
a. Line 1 : num=0, Line 2 : num+=1, Line 3 : function(string[num:],list1)
b. Line 1 : num=1, Line 2 : no code,Line 3 : list1 = function(string[num:],list1)
c. Line 1 : num=0, Line 2 : num+=1, Line 3 : list1 = function(string[num+1:],list1)
d. Line 1 : num=1, Line 2 : num+=1, Line 3 : list1 = function(string[num],list1)
View Answer
Ans. a
Explanation : Other options will not give the expected output.
10. John is visiting a zoo. After roaming for sometime, he finds that he has lost his way. John wants to reach the entry gate. He remembers Vars lce-Cream, a landmark which he saw while strolling in the zoo, John finds that there are 3 ways to reach Vans Ice-Cream from his current location and from Vans Ice Cream there are 4 ways to reach the ertry/exit gate. Considering the above scenario, identify the most suitable data structure that can be used to represent all possible ways to reach the entry exit gate from John’s current location?
a. Graph
b. Tree
c. Stack
d. Queue
View Answer
Ans. a
Explanation : Graph is the best data structure for the given case study.