In this article, we will be discussing some of the InfyTQ questions asked in the InfyTQ sample test released officially by Infosys. These InfyTQ sample questions will give you a fair idea about the difficulty level of the Infytq exam.
Have you registered for the Infosys InfyTQ certification exam? If you haven’t, here’s your chance.
If you’d like to read about InfyTQ Questions and Answers in Java, click here.
Check out InfyTQ Final Round Python Coding Questions here
Q1.
Consider the Python code below.
Assume that the necessary imports have been done.
class Shape (metaclass-ABCMeta) :n def _init_(self) :n print ( “I am in initâ€)n def draw_shape(self) :n passn def set_color(self) :n passnclass Circle(Shape) :n def draw_shape(self) :n print(“Draw Circleâ€)n
Which of the following statement(s) is/are TRUE?
i) Class Circle cannot be instantiated as it does not implement the set_color() method
ii) The above code will not compile because class Shape has two abstract methods
A. Both i) and ii) are True
B. Neither of i) or ii) is True
C. Only i) is True
D. Only ii) is True
Answer: C
Explanation:
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.
Q.2
Consider the below code snippet.
Identify the most efficient test data set for testing the below code using the ‘Logic Coverage’ technique.
if previous_year_percentage>=75 and previous_year_percentage<=85:n scholarship=5000nelif previous_year_percentage>85 and previous_year_percentage<=95:n scholarship=8000nelif previous_year_percentage>95:n scholarship=1000nelse:n scholarship=0n
A. 79, 87, 91, 99
B. 78, 80, 92, 99
C. 74, 77, 90, 100
D. 74, 75, 76, 84, 85, 86, 94, 95, 96, 97
Answer: C
Explanation:
Logic corresponds to the internal structure of the code and this testing is adopted for safety-critical applications such as software used in the aviation industry. This Test verifies the subset of the total number of truth assignments to the expressions.
Basically, you would be testing all the conditional statements for their respective True and False inputs. Here option C and option D provide logic coverage but the efficient one among them would be option C.
Q3.
Consider the following Python code snippet.
class ClassA :n _param1=200n def _init_(self) :n self._param1 = 100n def method1(self) :n #Line1____________n @staticmethodn def method2( ) :n #Line2_____________nobj1=ClassA( )nobj1.method1( )n#Line3_____________________n
Note: Line numbers are for reference only.
Fill in the blanks at Line1, Line2, and Line3 to get the output as 302.
Choose TWO CORRECT options
A: Line1:ClassA._param1=(ClassA._param1+1)+self._param1 Line2:print(self._param 1+1) Line3:self.method2()
B: Line1:ClassA._param1=(ClassA._param1+2)+ClassA._param1 Line2:print(ClassA._param1) Line3:ClassA.method2()
C: Line1:ClassA._param1=(ClassA._param1+1)+self._param1 Line2:print(ClassA._param1+1) Line3:ClassA.method2()
D: Line1:ClassA._param1=(ClassA._param1+2)+self._param1 Line2:print(ClassA._param 1) Line3:method2()
E: Line1:ClassA._param1=ClassA._param 1 +(self._param1+2) Line2:print(ClassA._param 1) Line3:ClassA.method2()
Answer: You are supposed to select C and E
Explanation:
A:
There will be an error because of a self._param1 call outside the class
B:
This option calls for ClassA.method2()
and method2 is defined as → print(ClassA._param1)
but the method2 is a static method and the values for ClassA.param1 has already been initialized in method1→ (ClassA._param1+2)+ClassA._param1
which is equivalent to → (200+2)+200
That ends up giving us 402 as the output.
C:
This option calls for ClassA.method2()
and method2 is defined as → print(ClassA._param1+1)
but the method2 is a static method and the values for ClassA.param1 has already been initialized in method1→ (ClassA._param1+1)+self._param1
which is equivalent to → (200+1)+100
That ends up giving us 302 as the output.
D:
This option calls for method2()
and method2 is not defined outside the classes so basically it would not return anything
E:
This option again would be a call for the method2→ ClassA.method2()
and method2 is defined as → print(ClassA._param1)
but the method2 is a static method and the values for ClassA.param1 has already been initialized in method1→ ClassA._param1+(self._param1+2)
which is equivalent to → 200+(100+2)
That ends up giving us 302 as the output.
So you can choose C and E.
Q4.
What is the output of the code given below?
def fun(input_list,index):n try:n output_list = [ 0 ]*len(input_list)n output_list [index] = input_list[index]/int(input_list[index+1])n return output_listn except ValueError :n print("Invalid value")n except ZeroDivisionError :n print("Division by zero")n finally :n print("End of function")ntry :n list1 = [2,4,'6',2,8]n list2 = fun(list1, 4) nexcept TypeError :n print ("Invalid type")nexcept IndexError :n print ("Invalid index")nfinally :n print ("End of program")n
A:
Invalid value
End of function
End of program
B:
Division by zero
End of function
End of program
C:
End of function
Invalid index
End of program
D:
End of function
Invalid type
End of program
Answer: C
Explanation: The syntax of the try-catch block would basically be:
try:
# Some Code….
except:
# optional block
# Handling of exception (if required)
finally:
# Some code …..(always executed)
So here, the list is passed to the function and the execution of the fun method begins, but there would be an index error because of output_list [index] = input_list[index]/int(input_list[index+1]), this would be caught in the second try-catch block. Since there is nothing to be caught in the first try-catch block it would execute and print the statement in the finally block of the first try-catch block which is End of function.
Next up, the index error will be handled and the respective statement Invalid index will be printed.
In the end, the finally block of the second try-catch block will be executed to print End of program.
So the order of the output would be:
End of function
Invalid index
End of program
Q5.
Consider the Python code below
class ClassA:n def first_method(self):n print("Johnny Johnny..., ")n def second_method (self):n print ("Yes Papa. ")n def third_method (self):n print("Eating Sugar..., ")nclass ClassB (ClassA):n def second_method (self):n super () .first_method ()n super ().second_method ()n super() .third_method ()n print("No Papa. ")n def third_method (self):n print("Telling Lies..., ")nclass ClassC (ClassB):n def first_method (self):n print("Open your mouth..., Ha. Ha. Ha.")n def second_method (self):n print ("No Papa. ")n def third_method (self):n super().second_method()n super() .third_method()n self. second_method()nobj_A=ClassA()nobj_B=ClassB()nobj_C=ClassC()n#Line 1n
Which among the below options if written at #Line 1, prints the rhyme correctly?
Choose TWO CORRECT options.
The expected output for your reference:
Johnny Johnny…,
Yes Papa.
Eating Sugar…,
No Papa.
Telling Lies…,
No Papa.
Open your mouth…,
Ha. Ha. Ha.
A:
obj_A.third_method()
obj_B.second_method()
obj_C.first_method()
obj_A.second_method()
B:
obj_C.third_method()
obj_B.second_method()
obj_A.first_method()
obj_C.first_method()
C:
obj_C.third_method()
obj_C.first_method()
D:
obj_B.second_method()
obj_B.third_method()
obj_C.second_method()
obj_C.first_method()
Answer: C
Explanation:
The super() builtin returns a proxy object (temporary object of the superclass) that allows us to access methods of the base class. In Python, super() has two major use cases. Allows us to avoid using the base class name explicitly and working with Multiple Inheritance.
In this particular case, the base class methods would be called whenever there is a super keyword used. The correct order of the execution would be when the instance is created related to ClassC and the method in the base class is used via C by the super keyword.
Q6.
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
Explanation:
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.
Q7.
What will be the output of the following Python code snippet?
def func (var1, var2, var3):n if(var1<=var2):n if(var3>-var2):n if(var1+var2>-var3):n print(-1)n else:n print(-2)n else:n if(var1+var3>var2):n print (-3)n else:n print (-4)nnfunc(156,2100,9500)n
A. -2
B. -3
C. -4
D. -1
Answer: D
Explanation:
The first condition is if(var1<=var2) → 156 <= 2100 #True
It will get inside to the next condition if(var3>-var2) → 9500 > (-2100) #True
It will get inside the next condition if(var1+var2>-var3) → (156+2100) > (-9500)#True
Final the last statement print will be executed which prints -1.
Q8.
Consider the below inputs:
input_linked_list (Head to Tail): 1 -> 2 -> 5 -> 3
input_stack (Top to Bottom): 4, 2, 5, 10
def generate (input_linked_list , input_stack):n temp= input_linked_list.get_head ( )n element=0n while(temp.get_next ( ) is not None):n temp.set_data (temp.get_data ( )+temp.get_next ( ). get_data ( )+element)n if temp.get_data ( ) %2 !=0:n temp.set_data(temp.get_data ( ) +input_stack.pop ( ) )n element=temp.get_data ( )n else:n input_stack.push (element )n element=temp.get_next ( ).get_data ( )n temp=temp.get_next ( )n temp.set_data(temp.get_data ( )+input_stack.pop ( ) )n
What will be the content of Input_linked_list from head to tail and input_stack from top to bottom after the execution of the function generate?
Assumption: Stack and LinkedList classes, with the necessary methods, are available
A:
input_linked_list (Head to Tail): 7 -> 14 -> 20 -> 5
input_stack (Top of Bottom): 5, 10
B:
input_linked_list (Head to Tail): 5 -> 7 -> 10 -> 5
input_stack (Top of Bottom): 2, 5, 10
C:
input_linked_list (Head to Tail): 7 -> 14 -> 20 -> 3
input_stack (Top of Bottom): 5, 10
D:
input_linked_list (Head to Tail): 7 -> 14 -> 20 -> 5
input_stack (Top of Bottom): 10
Answer: B
Explanation:
All the nodes are checked for the values to be a multiple of 2 and when they are not a value of the stack is popped and added to them and the previous values are overwritten.
Q9.
Consider the following Python code. Choose the correct option with respect to the number of static, instance and local variables in ClassOne:
Class ClassOne :n __var_one=1001n def__init__(self,var_two) :n self.__var_two=var_twon