Exercise: Questions on Output


Questions on Output : Question 1 :
What is the output of the following program :
def myfunc(a):
    a = a + 2
        a = a * 2
    return a

print myfunc(2)

8
16
Indentation Error
Runtime Error
Show Answer
Questions on Output : Question 2 :
What is the output of the expression : 3*1**3

27
9
3
1
Show Answer
Questions on Output : Question 3 :
What is the output of the following program :
print '{0:.2}'.format(1.0 / 3)

0.333333
0.33
0.333333:-2
Error
Show Answer
Questions on Output : Question 4 :
What is the output of the following program :
print '{0:-2%}'.format(1.0 / 3)

0.33
0.33%
33.33%
33%
Show Answer
Questions on Output : Question 5 :
What is the output of the following program :
i = 0
  while i < 3:
     print i
     i += 1
  else:
     print 0


0 1 2 3 0
0 1 2 0
0 1 2
Error
Show Answer
Questions on Output : Question 6 :
What is the output of the following program :
i = 0
while i < 5:
    print(i)
    i += 1
    if i == 3:
        break
else:
    print(0)


0 1 2 0
0 1 2
Error
None of the above
Show Answer
Questions on Output : Question 7 :
What is the output of the following program :
print 'cd'.partition('cd')

(‘cd’)
(”)
(‘cd’, ”, ”)
(”, ‘cd’, ”)
Show Answer
Questions on Output : Question 8 :
What is the output of the following program :
print 'abef'.partition('cd')

(‘abef’)
(‘abef’, ‘cd’, ”)
(‘abef’, ”, ”)
Error
Show Answer
Questions on Output : Question 9 :
What is the output of the following program :
print 'abcefd'.replace('cd', '12')

ab1ef2
abcefd
ab1efd
ab12ed2
Show Answer
Questions on Output : Question 10 :
What will be displayed by the following code?
def f(value, values):
    v = 1
    values[0] = 44
t = 3
v = [1, 2, 3]
f(t, v)
print(t, v[0])

1 1
1 44
3 1
3 44
Show Answer