Sail E0 Webinar

MCQs

Total Questions : 10
Question 1. What is the output of the code shown below?'The {} side {1} {2}'.format('bright', 'of', 'life')
  1.    Error
  2.    'The bright side of life'
  3.    'The {bright} side {of} {life}'
  4.    No output
 Discuss Question
Answer: Option A. -> Error


The code shown above results in an error. This is because we have switched from automatic field numbering to manual field numbering, that is, from {} to {1}. Hence this code results in an error.


Question 2. The output of the two codes shown below is the same. State whether this statement is true or false.bin((2**16)-1) '{}'.format(bin((2**16)-1))
  1.    True
  2.    False
  3.    Both I and II
  4.    Only I
 Discuss Question
Answer: Option A. -> True


The output of both of the codes shown above is '0b1111111111111111'. Hence the statement is true.


Question 3. In the code shown below, which function is the decorator?def mk(x):    def mk1():        print("Decorated")        x()    return mk1def mk2():    print("Ordinary")p = mk(mk2)p()
  1.    p()
  2.    mk()
  3.    mk1()
  4.    mk2()
 Discuss Question
Answer: Option B. -> mk()


In the code shown above, the function mk() is the decorator. The function which is getting decorated is mk2(). The return function is given the name p().


Question 4. What is the output of the code shown below?def mk(x):    def mk1():        print("Decorated")        x()    return mk1def mk2():    print("Ordinary")p = mk(mk2)p()
  1.    DecoratedDecorated
  2.    OrdinaryOrdinary
  3.    OrdinaryDecorated
  4.    DecoratedOrdinary
 Discuss Question
Answer: Option D. -> DecoratedOrdinary


The code shown above first prints the word "Decorated and then "ordinary. Hence the output of this code is: Decorated 
Ordinary


Question 5. What is the output of the code shown below?def f(x):    def f1(a, b):        print("hello")        if b==0:            print("NO")            return        return f(a, b)    return f1@fdef f(a, b):    return a%bf(4,0)
  1.    helloNO
  2.    helloZero Division Error
  3.    NO
  4.    hello
 Discuss Question
Answer: Option A. -> helloNO


In the code shown above, we have used a decorator in order to avoid the Zero Division Error. Hence the output of this code is:
hello
NO


Question 6. Which of the following formatting options can be used in order to add 'n' blank spaces after a given string 'S'?
  1.    print(-ns"%S)
  2.    print(-ns"%S)
  3.    print(%ns"%S)
  4.    print(%-ns"%S)
 Discuss Question
Answer: Option B. -> print(-ns"%S)


In order to add 'n' blank spaces after a given string 'S', we use the formatting option:("%-ns%S).


Question 7. The output of the code shown below is:s='{0}, {1}, and {2}'s.format('hello', 'good', 'morning')
  1.    'hello good and morning'
  2.    'hello, good, morning'
  3.    'hello, good, and morning'
  4.    Error
 Discuss Question
Answer: Option C. -> 'hello, good, and morning'


Within the subject string, curly braces designate substitution targets and arguments to be inserted either by position or keyword. Hence the output of the code shown above:'hello, good,and morning'.


Question 8. What is the output of the code shown?x=3.3456789'%f | %e | %g' %(x, x, x)
  1.    Error
  2.    '3.3456789 | 3.3456789+00 | 3.345678'
  3.    '3.345678 | 3.345678e+0 | 3.345678'
  4.    '3.345679 | 3.345679e+00 | 3.34568'
 Discuss Question
Answer: Option D. -> '3.345679 | 3.345679e+00 | 3.34568'


The %f %e and %g format specifiers represent floating point numbers in different ways. %e and %E are the same, except that the exponent is in lowercase. %g chooses the format by number content. Hence the output of this code is: '3.345679 | 3.345679e+00 | 3.34568'.


Question 9. What is the result of the expression shown below if x=56.236?print("%.2f"%x)
  1.    56.00
  2.    56.24
  3.    56.23
  4.    0056.236
 Discuss Question
Answer: Option B. -> 56.24


The expression shown above rounds off the given number to the number of decimal places specified. Since the expression given specifies rounding off to two decimal places, the output of this expression will be 56.24. Had the value been x=56.234 (last digit being any number
less than 5), the output would have been 56.23.


Question 10. What is the output of the code shown below?def d(f):    def n(*args):        return '$' + str(f(*args))    return n@ddef p(a, t):    return a + a*t print(p(100,0))
  1.    100
  2.    $100
  3.    $0
  4.    0
 Discuss Question
Answer: Option B. -> $100


In the code shown above, the decorator helps us to prefix the dollar sign along with the value. Since the second argument is zero, the output of the code is: $100.


Latest Videos

Latest Test Papers