InfyTQ Previous Year Python Questions 2022 : Python Output based Questions asked in previous editions.
You are here : Home >> InfyTQ Archive >> InfyTQ Python Questions
1. Consider the following code given below ?
class Glove:
def __init__(self,color):
self.__color = color
def get_color(self):
return self.__color
def set_color(self,color):
self.__color= color
class Minion:
def __init__(self,glove):
self.__glove=glove
self.__color="Yellow"
def get_glove(self):
return self.__glove
black_glove = Glove("Black")
red_glove = Glove("Red")
bob = Minion(black_glove)
black_glove.set_color(red_glove.get_color())
print(#line)
What should be placed in the place of #line to get the color of bob Minion’s glove ?
a. bob.__glove.__color
b. red_glove.get_color()
c. bob.get_glove().get_color()
d. bob.get_glove().__color
View Answer
Ans. c
2. Consider the following code :
class Customer:
def __init__(self,cust_id, cust_name):
self.__cust_id = cust_id
self.__cust_name = cust_name
self.__bill_amount = 0.0
class RegularCustomer(Customer):
def __init__(self,cust_id, cust_name):
self.__cust_id = cust_id
self.__cust_name = cust_name
self.__bill_amount = 0.0
self.__discount = 5
Identify the OOP principle(s) that has/have been implemented in the above code :
a. Only Encapsulation
b. Only Inheritance
c. Both Encapsulation and Inheritance
d. Only Polymorphism
View Answer
Ans. b
You are here : Home >> InfyTQ Archive >> InfyTQ Python Questions
3. Find the output of the following code :
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
4. Consider the following code :
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