Sail E0 Webinar

MCQs

Total Questions : 12 | Page 1 of 2 pages
Question 1. What is the output of the expression?
round(4.5676,2)?
  1.    4.5
  2.    4.6
  3.    4.57
  4.    4.56
 Discuss Question
Answer: Option C. -> 4.57


The function round is used to round off the given decimal number to the specified decimal places. In this case the number should be rounded off to two decimal places. Hence the output will be 4.57.


Question 2. What is the output of the functions shown below?divmod(10.5,5)divmod(2.4,1.2)
  1.    (2.00, 0.50)(2.00, 0.00)
  2.    (2, 0.5)(2, 0)
  3.    (2.0, 0.5)(2.0, 0.0)
  4.    (2, 0.5)(2)
 Discuss Question
Answer: Option C. -> (2.0, 0.5)(2.0, 0.0)


See python documentation for the function divmod.


Question 3. What is the output of the following piece of code?a={1:"A",2:"B",3:"C"}print(a.get(1,4))
  1.    1
  2.    A
  3.    4
  4.    Invalid syntax for get method
 Discuss Question
Answer: Option B. -> A


The get() method returns the value of the key if the key is present in the dictionary and the default value(second parameter) if the key isn't present in the dictionary.


Question 4. What is the output of the function shown below?hex(15)
  1.    f
  2.    0xF
  3.    0Xf
  4.    0xf
 Discuss Question
Answer: Option D. -> 0xf


The function hex() is used to convert the given argument into its hexadecimal representation, in lower case. Hence the output of the function hex(15) is 0xf.


Question 5. What is the output?d = {"john":40, "peter":45}d["john"]
  1.    40
  2.    45
  3.    john"
  4.    peter"
 Discuss Question
Answer: Option A. -> 40


Execute in the shell to verify.


Question 6. What is the output of the following snippet of code?total={}def insert(items):    if items in total:        total[items] += 1    else:        total[items] = 1insert('Apple')insert('Ball')insert('Apple')print (len(total))
  1.    3
  2.    1
  3.    2
  4.    0
 Discuss Question
Answer: Option C. -> 2


The insert() function counts the number of occurrences of the item being inserted into the dictionary. There are only 2 keys present since the key 'Apple' is repeated. Thus, the length of the dictionary is 2.


Question 7. What is called when a function is defined inside a class?
  1.    Module
  2.    Class
  3.    Another function
  4.    Method
 Discuss Question
Answer: Option D. -> Method




Question 8. What is the output of the below program?x = 50def func():    global x    print('x is', x)    x = 2    print('Changed global x to', x)func()print('Value of x is', x)
  1.    x is 50Changed global x to 2Value of x is 50
  2.    x is 50Changed global x to 2Value of x is 2
  3.    x is 50Changed global x to 50Value of x is 50
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> x is 50Changed global x to 2Value of x is 2


The global statement is used to declare that x is a global variable “ hence, when we assign a value to x inside the function, that change is reflected when we use the value of x in the main block.


Question 9. What is the output of the following code?a={}a[2]=1a[1]=[2,3,4]print(a[1][1])
  1.    [2,3,4].
  2.    3
  3.    2
  4.    An exception is thrown
 Discuss Question
Answer: Option B. -> 3


Now, a={1:[2,3,4],2:1} . a[1][1] refers to second element having key 1.


Question 10. What is called when a function is defined inside a class?
  1.    Module
  2.    Class
  3.    Another function
  4.    Method
 Discuss Question
Answer: Option D. -> Method




Latest Videos

Latest Test Papers