Sail E0 Webinar

MCQs

Total Questions : 11 | Page 1 of 2 pages
Question 1. What is the output of the code shown below?import math[str(round(math.pi)) for i in range (1, 6)]
  1.    ['3', '3', '3', '3', '3', '3']
  2.    ['3.1', '3.14', '3.142', '3.1416', '3.14159', '3.141582']
  3.    ['3', '3', '3', '3', '3']
  4.    ['3.1', '3.14', '3.142', '3.1416', '3.14159']
 Discuss Question
Answer: Option C. -> ['3', '3', '3', '3', '3']


The list comprehension shown above rounds off pi(3.141) and returns its value, that is 3. This is done 5 times. Hence the output is: ['3', '3', '3', '3', '3'].


Question 2. Suppose list1 is [1, 3, 2], What is list1 * 2 ?
  1.    [2, 6, 4].
  2.    [1, 3, 2, 1, 3]
  3.    [1, 3, 2, 1, 3, 2] .
  4.    [1, 3, 2, 3, 2, 1]
 Discuss Question
Answer: Option C. -> [1, 3, 2, 1, 3, 2] .


Execute in the shell and verify.


Question 3. What is the output of the code shown below?t=32.00[round((x-32)*5/9) for x in t]
  1.    [0]
  2.    0
  3.    [0.00]
  4.    Error
 Discuss Question
Answer: Option D. -> Error


The value of t in the code shown above is equal to 32.00, which is a floating point value. 'Float' objects are not iterable. Hence the code results in an error.


Question 4. What is the output of the following?print([i.lower() for i in "HELLO"])
  1.    ['h', 'e', 'l', 'l', 'o'].
  2.    'hello'
  3.    ['hello'].
  4.    hello
 Discuss Question
Answer: Option A. -> ['h', 'e', 'l', 'l', 'o'].


We are iterating over each letter in the string.


Question 5. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1) ?
  1.    3
  2.    5
  3.    25
  4.    1
 Discuss Question
Answer: Option D. -> 1




Question 6. What is the output when the following code is executed ?"Welcome to Python".split()
  1.    [Welcome", to", Python"].
  2.    (Welcome", to", Python")
  3.    {Welcome", to", Python"}
  4.    Welcome", to", Python"
 Discuss Question
Answer: Option D. -> Welcome", to", Python"


split() function returns the elements in a list.


Question 7. What is the output of the following code?import copya=[10,23,56,[78]]b=copy.deepcopy(a)a[3][0]=95a[1]=34print(b)
  1.    [10,34,56,[95]].
  2.    [10,23,56,[78]].
  3.    [10,23,56,[95]].
  4.    [10,34,56,[78]].
 Discuss Question
Answer: Option B. -> [10,23,56,[78]].


The above copy is deepcopy. Any change made in the original list isn't reflected.


Question 8. What will be the output?names1 = ['Amir', 'Bala', 'Charlie']names2 = [name.lower() for name in names1] print(names2[2][0])
  1.    None
  2.    a
  3.    b
  4.    c
 Discuss Question
Answer: Option D. -> c


List Comprehension are a shorthand for creating new lists.


Question 9. What will be the output?values = [[3, 4, 5, 1], [33, 6, 1, 2]] v = values[0][0]for lst in values:    for element in lst:        if v > element:            v = element print(v)
  1.    1
  2.    3
  3.    5
  4.    6
 Discuss Question
Answer: Option A. -> 1


Execute in the shell to verify.


Question 10. What is the output of the following piece of code?a=list((45,)*4)print((45)*4)print(a)
  1.    180[(45),(45),(45),(45)].
  2.    (45,45,45,45).[45,45,45,45].
  3.    180[45,45,45,45].
  4.    Syntax error
 Discuss Question
Answer: Option C. -> 180[45,45,45,45].


(45) is an int while (45,) is a tuple of one element. Thus when a tuple is multiplied, it created references of itself which is later converted to a list.


Latest Videos

Latest Test Papers