Company-Specific Courses
Free Resources
About Us



InfyTQ Questions | Python MCQs | Final Round

Published on 16 Apr 2021

This article covers the InfyTQ Final Round MCQs in Python. Post the initial Qualifying Round, the Final Round in InfyTQ is what determines whether candidates get the certificate of Infosys Certified Software Programmer and also potentially land a job offer in Infosys. What's covered in this article is solutions in Python to the InfyTQ Questions (MCQs), which are part of the official sample paper.

InfyTQ Questions and Answers | Python MCQs

Given below are the InfyTQ Questions (Python MCQs) that were covered in the Final Round.

Question 1:

Consider the following Python code snippet.

class ClassA:
    def __init__(self):
        self.__param1 = 100
    def method1(self):
        #Line 1_________
    def method2( ):
        #Line 2_________ 
obj1=ClassA( ) 
#Line 3________________ 

Note: Line numbers are for reference only.

Fill in the blanks at Line1, Line2 and Line3 to get the output 302.

Option A


Line2:print(self._param1+1) Line3:self.method2()

Option B

Line 1:ClassA._param1=(ClassA._param1+2)+ClassA._param1

Line2:print(ClassA._param1) Line3:ClassA.method2()

Option C

Line 1:ClassA._param1=(ClassA._param1+1)+self._param1

Line2:print(ClassA._param1+1) Line3:ClassA.method2()

Option D

Line 1:ClassA._param1=(ClassA._param1+2)+self._param1

Line2:print(ClassA._param1) Line3:method2()

Option E:

Line 1:ClassA._param1=ClassA._param1+(self._param1 + 2)

Line2:print(ClassA._param1) Line3:ClassA.method2()

Answer: C and E


A. You cannot have a self.method2() outside the class which would throw an error

B. Option B would give 402

C. Would give 302

D. Would throw an error because method2() in Line3 does not have any reference

E. Would also give 302

Question 2:

Which of the following statements can replace Line1 and Line2 in the below Python code to get output as ‘kcjh’? 

def func1(st1):
    for ch in st1:
        if(ch!="a" and ch!="e" and ch!="i" and ch!="o" and ch!="u"):
        if(ch == "#"):
     while(not stack1.is_empty()): 
            result+=stack1.pop( )
     print ( result )
func1 ( st )

Assumption: Stack class, with the necessary methods, is available.

A: Line 1: stack1.pop() Line2: stack1.push(ch)

B: Line 1: stack1.push(ch) Line2: stack1.push(ch)

C: Line 1: stack1.push(ch) Line2: stack1.pop()

D: Line 1: stack1.pop() Line2: stack1.pop()

Answer: C


If we are supposed to get the desired output we are supposed to do the following:

  1. Separate all the vowels
  2. Remove all the '#'s
  3. Push all the other characters into the stack and finally pop them

This can be only done when we follow the coding lines given in option C.

Question 3:

Alister is a Python developer who has written the below code. He desires the output to be 123 Volvo, but, he is unable to proceed due to an error.

class Car:
    def __init__( self,car_id,car_name):
        self.__car_id=car_id                      #Line 1
        self.car_name=car_name            #Line 2

car1=Car(123, "Volvo")                         #Line 3
print(car1.car_id(),car1.car_name)     #Line 4 

Choose two options from below which he should implement to get the desired output?

Note: Line numbers are for reference only.

A: Add a method to the Car class as follows: def get_car_id(self):return car_id

B: Add a method to the Car class as follows: def get_car_id(self): return self._car_id

C: Change Line 4to : print(car1.get_car_id(),car1.car_name)

D: Change Line 4 to : print(car1._car_id,car1.car_name)

Answer: B and C


As the variable __car_id is a private variable, we would have to use a separate method to use the variable outside the class. The same has to be used in the print statement.

Question 4:

Consider the following Python function for a vehicle management system. Objective of the code is to record details of vehicles-

def vehicle_record_no,mileage,veh_type,purpose,kickstart,no_of_gears,miles_run ) :
      if(veh_type == “TwoWheeler”) :
            record=reg_no+”:TwoWheeler:”+ str(mileage)+”:”+kickstart
      elif(veh_type == “FourWheeler”) :
            if(purpose == “Commercial”) :
                    record=record+”:Commercial FourWheeler:”+miles_run
       return record


What will be the optimal class structure if this was to be re-written in Object oriented programming?

A: 4 independent classes: Vehicle, TwoWheeler, FourWheeler, CommericalFourWheeler

B: 3classeswith inheritance: TwoWheeler and FourWheeler inherit from Vehicle

C: 4 classes with inheritance: TwoWheeler, FourWheeler and CommericalFourWheeler which inherit from Vehicle

D: 4 classes with inheritance: TwoWheeler and FourWheeler inherit from Vehicle; CommericalFourWheeler inherits from FourWheeler

Answer: D


The main objective of object-oriented programming is code reusability and in the above case it can be done by segregation the parameters into parent-child class pairs. The optimum design would be as given below:

So in this segregation the common features of vehicle class can be used by all its child classes and likewise the common features of four wheeler class can be used by the commercial class.

This arrangement is suggested in option D 

Question 5:

Consider the Hashing methods given below:

i)  h(key) = key%10

ii) h(key) = key%25

iii) h(key) = key%50

Which of the hashing methods would NOT lead to collision when the following values are to be stored in the hash table?

80, 20, 35, 45, 25, 90

A: Only iii)

B: Both ii) and iii)

C: Both i) and iii)

D: All i), ii) and iii)

Answer: A


Only when the numbers are divided by 50 we would get different remainders for all the respective numbers. Remaining numbers would at least give one duplicate remainder.

Question 6:

Number 14 needs to be searched using BINARY SEARCH in the following sorted list of numbers:

1, 3, 7, 9, 14, 19, 45

How many comparisons will be required to conclude that the number 14 is found at 5th position?

Note: We have used integer division for finding the middle element and the index starts with 0(zero)

A: 2

B: 3

C: 4

D: 1

Answer: B


1st iteration: low= 0

high= 6

mid= (0+6)//2 = 3

a[3]<key, which means 9<14

2nd iteration: low = mid+1 = 4

high = 6

mid = (4+6)//2 = 5

a[5]>key, which means 19>14

3rd iteration: low = 4

high = mid - 1 = 4

mid = (4+4)//2 = 4

a[4]==key, which means 14==14.

Question 7:

What will be the output of the below code?

class Sample: 
    def __init__(self,val):
    def method1(self):
        return self.val//2

class Parent:
    def __init__(self, val1):
    def method2 (self):
        return self.num1

class Child(Parent):
    def __init__(self,val1, val2, obj):
    def method1 (self):
        return (self.obj_x.method1()+self.num1) 

obj2=Child(15,20, obj1) 
print(obj2.method1()+obj2.method2() +Parent.counter)

A: 69

B: 43

C: 70

D: 71

Answer: C


The combined sum of obj2.method1()+obj2.method2()+Parent.counter would be (25+45+0) so the sum would be 70.

Question 8:

Consider the below code:

my_queue1 = Queue(3)
my_queue2 = Queue(3)
for index in range(0, 3):
    my_queue1.enqueue(index *3)
for index in range(0, 3):
    if(index == 2):
    my_queue2.enqueue(my_queue1.dequeue ( ) )

Assumption: Queue class, with the necessary methods, is available

What is the status of my_queue 1 and my queue2 after the execution of above code?

In the options, consider the elements of the queue from Front to Rear

A: my_queue 1: 6, my_queue2: 0,3

B: my_queue 1: 6, my queue2: 0, 3, 12

C: my queue1: Queue is empty, my_queue2: 0, 3, 12

D: my_queue1: 0,3,6, my_queue2:0, 3, 12

Answer: C


Here the queue1 is being filled as 0, 3, 6 (front to rear). When this is dequeued the order would be 0 first, then 3 and finally 6. So the 1st dequeue would give us 0, so now queue2 becomes 0 (front to rear). Next dequeue of queue1 would give us 3, which would be the 2nd enqueue for queue2. So now queue2 would be 0, 3 (front to rear). The dequeue of queue1 would stop here as the index reaches 2. Final enqueue of queue2 would happen with a 12. So finally queue2 becomes 0, 3, 12 (front to rear).

Question 9:

What will be the output of the code below? 

class ClassA: 
     def __init__(self,val1):
     def method_a(self):
             return 10+self.value 
class ClassB: 
      def __init__(self,val2):
      def method_b(self,obj):
              return obj.method_a()+self.num


A: 60

B: 50

C: 30

D: 40

Answer: A


obj.method_a() would return a value 10+self.value where self.value() is 20 resulting return would be 30. self.num is already stored as 30. Therefore the final output from obj2.method_b(obj_1) is 30+30 that is 60.

Question 10:

Consider the python code below.

Assume that necessary imports have been done. 

class Shape (metaclass=ABCMeta): 
    def __init__(self):
        print("I am in init")

    def draw_shape(self):

     def set_color(self):

class Circle(Shape): 
       def draw_shape(self):
           print("Draw Circle"

Which of the following statement(s) is/are TRUE?

i) Class Circle cannot be instantiated as it does not implement set_color() method

ii) The above code will not execute because class Shape has two abstract methods

A: Only i) is True

B: Only ii) is True

C: Both i) and ii) are True

D: Neither of i) or ii) is True

Answer: A


The abstract base class may have more than one abstract method.

Here class Shape has more than one abstract method. It is totally possible for a base class to have more than one abstract method but all these methods have to be implemented by the child class or a TypeError would occur.

Statement 1 says that the child class Circle cannot be instantiated which is true, as it does not implement all the abstract methods of the base class.

Statement 2 says the code will not compile because of the base class having more than one abstract method which is false.

 If you want to check out the video explanation of these questions, please watch the video below.

Suggested Articles:

InfyTQ Questions and Answers | Python Qualifying Round

InfyTQ 2022 batch | Infosys InfyTQ Registration & Process

HackWithInfy 2021 | Infosys Coding Contest for 2022 batch

InfyTQ Questions and Answers | InfyTQ Aptitude for Qualifying Round

InfyTQ Questions and Answers | Java Qualifying Round

InfyTQ Final Round Python Coding Questions

InfyTQ Questions | InfyTQ Final Round DBMS Questions

InfyTQ Questions and Answers | Java Qualifying Round

InfyTQ Questions | InfyTQ Final Round Java MCQs

If you have any feedback about this article and want to improve this, please write to
Explore 'infosys'