Formatting Python Multiple Choice Questions. Multiple Choice Questions on Formatting in Python Programming Language Part 1.
Formatting Python Multiple Choice Questions
What will be the output of the following Python expression if X=345 ??
print(“%06d”%X)
a) 345000
b) 000345
c) 000000345
d) 345000000
What will be the output of the following Python code ??
‘%x %d’ %(255, 255)
a) ‘ff, 255’
b) ‘255, 255’
c) ‘15f, 15f’
d) Error
What will be the output of the following Python code ??
‘{0:.2f}’.format(1.234)
a) ‘1’
b) ‘1.234’
c) ‘1.23’
d) ‘1.2’
What will be the output of the following Python code ??
‘{a}, {0}, {abc}’.format(10, a=2.5, abc=[1, 2])
a) Error
b) ‘2.5, 10, [1, 2]’
c) 2.5, 10, 1, 2
d) ’10, 2.5, [1, 2]’
MCQs Python
What will be the output of the following Python code ??
t = ‘%(a)s, %(b)s, %(c)s’
t % dict(a=’hello’, b=’world’, c=’universe’)
a) ‘hello, world, universe’
b) ‘hellos, worlds, universes’
c) Error
d) hellos, world, universe
What will be the output of the following Python code ??
s=’%s, %s & %s’
s%(‘mumbai’, ‘kolkata’, ‘delhi’)
a) mumbai kolkata & delhi
b) Error
c) No output
d) ‘mumbai, kolkata & delhi’
The expression is shown below results in an error ??
print(“-%5d0”,989)
a) True
b) False
What will be the output of the following Python expression if x=22.19 ??
print(“%5.2f”%x)
a) 22.1900
b) 22.00000
c) 22.19
d) 22.20
Formatting Python Multiple Choice Questions
What will be the output of the following Python expression if x=56.236 ??
print(“%.2f”%x)
a) 56.00
b) 56.24
c) 56.23
d) 0056.236
What will be the output of the following Python expression if the value of x is 34 ??
print(“%f”%x)
a) 34.00
b) 34.0000
c) 34.000000
d) 34.00000000
What will be the output of the following Python expression if X = -122 ??
print(“-%06d”%x)
a) -000122
b) 000122
c) –00122
d) -00122
What will be the output of the following Python code ??
s='{0}, {1}, and {2}’
s.format(‘hello’, ‘good’, ‘morning’)
a) ‘hello good and morning’
b) ‘hello, good, morning’
c) ‘hello, good, and morning’
d) Error
Formatting Python Multiple Choice Questions
What will be the output of the following Python code snippet ??
a=’hello’
q=10
vars()
a) {‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}
b) {……Built in names set by Python……}
c) {‘a’ : ‘hello’, ‘q’ : 10}
d) Error
What will be the output of the following Python code snippet ??
‘%(qty)d more %(food)s’ %{‘qty’:1, ‘food’: ‘spam’}
a) Error
b) No output
c) ‘1 more foods’
d) ‘1 more spam’
What will be the output of the following Python code snippet ??
x=3.3456789
‘%s’ %x, str(x)
a) Error
b) (‘3.3456789’, ‘3.3456789’)
c) (3.3456789, 3.3456789)
d) (‘3.3456789’, 3.3456789)
Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’ ??
a) print(“-ns”%S)
b) print(“-ns”%S)
c) print(“%ns”%S)
d) print(“%-ns”%S)
Formatting Python Multiple Choice Questions
The output of the two codes shown below is the same ??
i. ‘{0:.2f}’.format(1/3.0)
ii. ‘%.2f’%(1/3.0)
a) True
b) False
What will be the output of the following Python expression if x=456 ??
print(“%-06d”%x)
a) 000456
b) 456000
c) 456
d) error
What will be the output of the following Python code snippet ??
X=”my-android”
print(“%56s”,X)
a) 56 blank spaces before my-android
b) 56 blank spaces before my and android
c) 56 blank spaces after my-android
d) no change
What will be the output of the following Python code snippet ??
X=”hi”
print(“05d”%X)
a) 00000hi
b) 000hi
c) hi000
d) error
Read More