Technical Round Aptitude Questions
Q1 Assume that a dictionary has a data in the form of { key1:value1,key2:value2...}
my_library={
103:"Alice in Wonderland",
104:"The Turning Point",
105:"Wings on Fire",
106:"Harry Potter"}
print(my_library[104])
What do you think my_library[104] would point do?
a] 104
b] This is a dictionary and not a list
c] The Turning Point
d] There are only 4 elements here, what on earth are you calling index 104 for.
Ans:- c] The Turning Point
Q2 What is the output of the following code snippet?
my_list=[0]*5
for index in range(1,5):
my_list[index]=(index-1)*10
print(my_list)
a] [0,0,0,0,0]
b] [10,20,30,40,50]
c] [0,10,20,30,40]
d] [0,0,10,20,30]
Ans:- d] [0,0,10,20,30]
Q3 Suppose you have a bank account no what do you think will be its data type?
eg:- 0000777888119
a] int
b] string
c] float
Ans:- b] String
Q4 Which of the following is a valid statement?
class A():
def __init__(self , b):
self.x=100
self.b=b
class B():
def __init__(self):
self.y=200
a] a=A(b)
b] a(B()).y.b
c] a=A(B())
d]a(B()).y
Ans:- c] a=A(B())
Q5 Output of the following Snippet?
class Test1(Exception):pass
class Test2:
def sample(self):
try:
raise Test1
except Test1:
print(1)
finally:
print(2)
try:
Test2().sample()
except Test1:
print(3)
finally:
print(4)
a] 1 2
b] 123
c] 1 2 3 4
d] 1 2 4
Ans:- d] 1 2 4
Q6 Output of the following code snippet?
class A:
def __init__(self):
self.__x=100
a=A()
a.__x=200
print(a.__x)
a] 100
b] None
c] 200
d] Error
Ans:- c] 200
Q7 What id the output of the following code Snippet?
l=[100.5,30.465,-1.22,20.15]
l.insert(1,-100.5)
l.pop(0)
l.sort()
print(l[0])
a] 100.5
b] 20.15
c] -100.5
d] 30.465
Ans:- c] -100.5
Q8 What id the output of the following code Snippet?
class Parent:
def mtd (self):
print("Parent")
class Child(Parent):
def mtd(self):
print("Child")
def change(o=Child()):
o.mtd()
change(Child())
a] Child
b]Parent
c] Error
d] None
Ans:- a] Child
Q9 What id the output of the following code Snippet?
class Parent:
def mtd (self):
print("Parent")
class Child(Parent):
def mtd(self):
print("Child")
def change(o=Parent()):
o.mtd()
change(Parent())
a] Child
b]Parent
c] Error
d] None
Ans:- b]Parent
Q10 What id the output of the following code Snippet?
class Parent:
def __init__(self,num):
self.__num=num
def get_num(self):
return self.__num
class Child(Parent):
def show(self):
print("This is in child class")
son=Child(100)
print(son.get_num())
son.show()
a] 100 This is in child class
b] Error: Child object,obj does not have __num as an attribute
c] Error: Child class should have a constructor
d] Error: Child object cannot invoke a parent method
Ans:- a] 100 This is in child class
Q11 What id the output of the following code Snippet?
class Parent:
def __init__(self,num):
self.__num=num
def get_num(self):
return self.__num
class Child(Parent):
__num=10
def get_num(self):
return self.__num
def show(self):
print("This is in child class")
son=Child(100)
print(son.get_num())
son.show()
a] 10 This is in child class
b] Error: Child object,obj does not have __num as an attribute
c] Error: Child class should have a constructor
d] Error: Child object cannot invoke a parent method
Ans:- a] 10 This is in child class
Q12 What is the output of the following code snippet?
a =-10
b=-200
c=2000
d=4000
if (a*b >=d):
if(d>c):
if(d%c!=0):
print(11)
else:
print(22)
else:
if(b/a >0):
if (a<b or d%c!=0):
print(33)
else:
print(44)
a] 11
b] 22
c] 33
d] 44
Ans:- d] 44
Q13 Predict the output of the following code?
class Customer:
def __init__(self,name,mobile):
self.name=name
self.mobile=mobile
class Mobile:
def __init__(self,brand):
self.brand=brand
def unlock (self,cover):
cover.color="yellow"
class Cover:
def __init__(self):
self.color="red"
Customer("Cust1",Mobile("Apple")).mobile.unlock(Cover())
print(Cover().color)
a] red
b]Yellow
c]Error
Ans:- a] red
Q14 Predict the output of the following code?
class Mobile:
def __init__(self,brand,case):
self.brand=brand
self.case=case
def display(self):
print(self.case.color)
class Case:
def __init__(self,color):
self.color=color
c1=Case("Black")
c2=Case("White")
m1=Mobile("Hony",c1)
c1.color="Green"
m1.display()
a] Black
b] White
c] Green
Ans:- c] Green
0 Comments