Infytq Python Mock-I


1. Consider the Python code below.
 Assume that the necessary imports have been done.


  class Shape (metaclass-ABCMeta):
      def _init_(self):
          print("I am in init")
      def draw_shape(self):
          pass
      def set_color(self):
          pass
  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 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.


(c) is the correct option.


2. Consider the Python code below.
 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:
      scholarship=5000
  elif previous_year_percentage>85 and previous_year_percentage<=95:
      scholarship=8000
elif previous_year_percentage>95:
      scholarship=1000
else:
      scholarship=0

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) 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


(c) is the correct option.



3. Consider the following code snippet written in Python:


  def fun(num):
      if num<1:
          return 0
      elif num%2==0:
          return fun(num-1)
      else:
          return num+fun(num-2)
print(fun(8))


   a) 8
   b) 12
   c) 20
   d) 16


(c) is the correct option.




4.Consider the below code:



 def vending_machine(insert_money,item_id):
    if item_id == 101 and insert_money:
        #Line1
    #Line2
 insert money= True
 item_id = 101
 print(vending_machine(insert_money.item_id))

Identify the statements to be replaced in Line 1 and Line 2 respectively such that the output is as below:

Disperse the product
Function executed successfully

a)    Line1 : return "Disperse the product"
       Line2 : return "Function executed successfully"
b)    Line1 : print ("Disperse the product")
       Line2 : return "Function executed successfully"
c)    Line1 : return "Disperse the product"
       Line2 : print ("Function executed successfully")
d)    Line1 : print ("Disperse the product")
       Line2 : print ("Function executed successfully")


(c) is the correct option.



5.Assume,Number1=7,Number2=8:



1.(Number1<Number2)and(Number1!=Number2)
2.(Number2>=Number1)or(Number1>Number2)
3. not(Number1==Number2)


Identify the expressions which would result in True?

   a) All of these
   b) 1,2
   c) 2,3
   d) 1,3


(c) is the correct option.



6.What is the outcome of the following pseudo-code?:



  input Counter
  while(Counter<5) do
    Counter=Counter+1
    display Counter
  end-while

Assume that the input value provided to variable, Counter is 1.

   a) 2,3,4,5
   b) 2,3,4
   c) 1,2,3,4
   d) 1,2,3,4,5


(c) is the correct option.



7.When the values of var1=7, var2=6 and var3=3, which among the following logical expressions would be FALSE?:



i. (var1+var2)>(var3) and (var1*var2+var3)>=(var3+var1)
ii. (var1*var2)>(var3*var1) and (var1*var2)<=(var1*var2*var3)
iii. (var1*var3)>(var1*var2*var3) or (var1*var3)<=(var2*var3)
iv. not((var1*var3)>(var3*var1) and (var1*var3)<=(var2*var3))


   a) i
   b) ii
   c) iii
   d) iv


(c) is the correct option.



8.Consider a Python dictionary which represents a ship's crew.?



  ship_skrew={
    "co-captain":"Jack"
    "Chief officer":"Mack"
    "Chief Steward":"Harry"
    "Chief Cook":"male"
}

Jack has been promoted as a Captain and a new member Tom has joined as a Co-Captain.
What code should be written in order to have these details updated in the dictionary.
Choose TWO CORRECT options from below.



A) ship_crew['Co-Captain']="Tom"
    ship_crew['Co-Captain']=ship_crew['Captain']
B) ship_crew['Co-Captain']="Tom"
    ship_crew['Captain']="Jack"
C) ship_crew['Captain']=ship_crew['Co-Captain']
    ship_crew['Co-Captain']="Tom"
D) ship_crew['Captain']="Tom"
    ship_crew['Co-Captain']="Jack"

   a) 2,3,4,5
   b) 2,3,4
   c) 1,2,3,4
   d) 1,2,3,4,5


(c) is the correct option.