Python 3 MCQ (SET-3) – Multiple Choice Questions and Answers

  1. What will be the output after the following statements?
    x = {0:4, 1:8, 2:16, 3:32}
    print(list(x.values())[2])
    a. [4, 8]
    b. [4, 8, 16]
    c. 16
    d. 8
  2. What will be the output after the following statements?
    x = {0:4, 1:8, 2:16, 3:32}
    print(x.items())
    a. dict_items(4, 8, 16, 32)
    b. dict_items([4, 8, 16, 32])
    c. dict_items[0, 1, 2, 3]
    d. dict_items([(0, 4), (1, 8), (2, 16), (3, 32)])
  3. What will be the output after the following statements?
    x = {5:4, 8:8, 3:16, 9:32}
    print(sorted(x.items()))
    a. [4, 8, 16, 32]
    b. [(3, 16), (5, 4), (8, 8), (9, 32)]
    c. [3, 5, 8, 9]
    d. [(4, 5), (8, 8), (16, 3), (32, 9)]
  4. What will be the output after the following statements?
    x = 7
    if x > 5:
    print(20)
    a. 20
    b. 5
    c. x
    d. 7
  5. What will be the output after the following statements?
    x = 8
    if x > 8:
    print(20)
    else:
    print(10)
    a. 20
    b. x
    c. 10
    d. 8
  6. What will be the output after the following statements?
    x = 40
    if x > 10:
    print(20)
    elif x == 40:
    print(10)
    else:
    print(30)
    a. 20
    b. 40
    c. 10
    d. 30
  7. What will be the output after the following statements?
    x = 15
    if x > 15:
    print(0)
    elif x == 15:
    print(1)
    else:
    print(2)
    a. 0
    b. 1
    c. 2
    d. 15
  8. What will be the output after the following statements?
    x = 5
    if x > 15:
    print(‘yes’)
    elif x == 15:
    print(‘equal’)
    else:
    print(‘no’)
    a. 15
    b. yes
    c. equal
    d. no
  9. What will be the output after the following statements?
    x = 50
    if x > 10 and x < 15:
    print(‘true’)
    elif x > 15 and x < 25:
    print(‘not true’)
    elif x > 25 and x < 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  10. What will be the output after the following statements?
    x = 25
    if x > 10 and x < 15:
    print(‘true’)
    elif x > 15 and x < 25:
    print(‘not true’)
    elif x > 25 and x < 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  11. What will be the output after the following statements?
    x = 15
    if x > 10 and x <= 15:
    print(‘true’)
    elif x > 15 and x < 25:
    print(‘not true’)
    elif x > 25 and x < 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  12. What will be the output after the following statements?
    x = 25
    if x > 10 and x <= 15:
    print(‘true’)
    elif x >= 15 and x < 25:
    print(‘not true’)
    elif x >= 25 and x < 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  13. What will be the output after the following statements?
    x = 25
    if x >= 10 and x <= 15:
    print(‘true’)
    elif x >= 15 and x <= 25:
    print(‘not true’)
    elif x >= 25 and x <= 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  14. What will be the output after the following statements?
    x = 20
    if x <= 10 or x >= 75:
    print(‘true’)
    elif x <= 15 or x >= 55:
    print(‘not true’)
    elif x <= 25 or x >= 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  15. What will be the output after the following statements?
    x = 30
    if x <= 10 or x >= 75:
    print(‘true’)
    elif x <= 15 or x >= 55:
    print(‘not true’)
    elif x <= 25 or x >= 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  16. What will be the output after the following statements?
    x = 80
    if x <= 10 or x >= 75:
    print(‘true’)
    elif x <= 15 or x >= 55:
    print(‘not true’)
    elif x <= 25 or x >= 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  17. What will be the output after the following statements?
    x = 60
    if x <= 10 or x >= 75:
    print(‘true’)
    elif x <= 15 or x >= 55:
    print(‘not true’)
    elif x <= 25 or x >= 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  18. What will be the output after the following statements?
    x = 68
    if x <= 50 and x >= 25:
    print(‘true’)
    elif x <= 60 or x >= 55:
    print(‘not true’)
    elif x <= 70 and x >= 35:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  19. What will be the output after the following statements?
    x = 99
    if x <= 30 or x >= 100:
    print(‘true’)
    elif x >= 50 and x <= 80:
    print(‘not true’)
    elif x >= 100 or x <= 75:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  20. What will be the output after the following statements?
    x = 70
    if x <= 30 or x >= 100:
    print(‘true’)
    elif x <= 50 and x == 50:
    print(‘not true’)
    elif x >= 150 or x <= 75:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  21. What will be the output after the following statements?
    x = 40
    y = 25
    if x + y >= 100:
    print(‘true’)
    elif x + y == 50:
    print(‘not true’)
    elif x + y <= 90:
    print(‘false’)
    else:
    print(‘not false’)
    a. true
    b. false
    c. not true
    d. not false
  22. What will be the output after the following statements?
    x = 1
    while x < 10:
    print(x, end=”)
    x = x + 1
    a. 123456789
    b. 1
    c. 10
    d. 2
  23. What will be the output after the following statements?
    x = 0
    while x < 10:
    print(x, end=”)
    x += 4
    a. 0123456789
    b. 123456789
    c. 4123456789
    d. 048
  24. What will be the output after the following statements?
    x = 0
    y = 4
    while x + y < 10:
    print(x, end=”)
    x += 1
    a. 012345
    b. 0123456789
    c. 4123456789
    d. 048
  25. What will be the output after the following statements?
    x = 0
    y = 4
    while x + y < 10:
    x += 1
    print(x, end=”)
    a. 012345
    b. 0123456
    c. 123456
    d. 0123456
  26. What will be the output after the following statements?
    x = 1
    y = 4
    while x * y < 10:
    print(y, end=”)
    y += 1
    a. 012345
    b. 456789
    c. 123456789
    d. 0123456789
  27. What will be the output after the following statements?
    x = 1
    y = 4
    while x * y < 10:
    print(y, end=”)
    x += 1
    y += 1
    a. 4
    b. 48
    c. 148
    d. 0123456789
  28. What will be the output after the following statements?
    x = 1
    y = 4
    while x * y <= 10:
    print(x, end=”)
    x += 1
    y += 1
    a. 4
    b. 48
    c. 14
    d. 12
  29. What will be the output after the following statements?
    x, y = 2, 5
    while y – x < 5:
    print(x*y, end=’ ‘)
    x += 3
    y += 4
    a. 1045
    b. 10 45
    c. 34
    d. 3 4 10 45
  30. What will be the output after the following statements?
    x, y = 0, 1
    while y < 10:
    print(y, end=’ ‘)
    x, y = y, x + y
    a. 1 1 2 3 5 8
    b. 112358
    c. 0123456789
    d. 0 2 4 6 8
  31. What will be the output after the following statements?
    x = 1
    while x < 4:
    x += 1
    y = 1
    while y < 3:
    print(y, end=’ ‘)
    y += 1
    a. 1 1 2 2
    b. 1 1 2 2 3 3 4 4
    c. 1 2 3 4
    d. 1 2 1 2 1 2
  32. What will be the output after the following statements?
    x = y = 1
    while x < 4:
    x += 1
    while y < 3:
    print(y, end=’ ‘)
    y += 1
    a. 1 1 2 2
    b. 1 2
    c. 1 2 3 4
    d. 1 2 1 2 1 2
  33. What type of loop is this?
    x = 1
    while x < 5:
    print(x, end=”)
    a. Closed loop
    b. One time loop
    c. Infinite loop
    d. Evergreen loop
  34. What will be the output after the following statements?
    x = ‘hello’
    for i in x:
    print(i, end=”)
    a. h
    b. hello
    c. h e l l o
    d. i x
  35. What will be the output after the following statements?
    for i in range(5):
    print(i, end=”)
    a. 5
    b. 1 5
    c. 012345
    d. 01234
  36. What will be the output after the following statements?
    for i in range(1,5):
    print(i, end=”)
    a. 15
    b. 12345
    c. 1234
    d. 012345
  37. What will be the output after the following statements?
    for i in range(1,25,5):
    print(i, end=’ ‘)
    a. 1 6 11 16 21
    b. 1 5 10 15 20 25
    c. 1 5 25
    d. 16111621
  38. What will be the output after the following statements?
    x = [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]
    for i in x:
    print(i, end=”)
    a. P
    b. python
    c. Pytho
    d. Python
  39. What will be the output after the following statements?
    x = (‘a’, ‘b’, ‘c’, ‘d’)
    for i in x:
    print(i, end=’ ‘)
    a. abcd
    b. a b c d
    c. False
    d. True
  40. What will be the output after the following statements?
    x = {‘x’, ‘z’, ‘y’}
    for i in x:
    print(i, end=”)
    a. x z y
    b. xzy
    c. False
    d. True
  41. What will be the output after the following statements?
    x = {‘z:1’, ‘y:2’, ‘x:3′}
    for i in x:
    print(i, end=’ ‘)
    a. x y z
    b. 1 2 3
    c. x:3 y:2 z:1
    d. True
  42. What will be the output after the following statements?
    x = [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]
    for i in enumerate(x):
    print(i, end=”)
    a. (‘P’)(‘y’)(‘t’)(‘h’)(‘o’)(‘n’)
    b. python
    c. python
    d. (0, ‘P’)(1, ‘y’)(2, ‘t’)(3, ‘h’)(4, ‘o’)(5, ‘n’)
  43. What will be the output after the following statements?
    x = {‘x’:1, ‘y’:2, ‘z’:3}
    for i in x:
    print(i, end=’ ‘)
    a. x y z
    b. 1 2 3
    c. x:1 y:2 z:3
    d. True
  44. What will be the output after the following statements?
    x = {‘x’:1, ‘y’:2, ‘z’:3}
    for i, j in x.items():
    print(i, j, end=’ ‘)
    a. x y z
    b. x 1 y 2 z 3
    c. x:1 y:2 z:3
    d. x, 1, y, 2, z, 3
  45. What will be the output after the following statements?
    x = [‘p’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]
    y = [‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’]
    for i in zip(x, y):
    print(i, end=”)
    a. (‘P’)(‘y’)(‘t’)(‘h’)(‘o’)(‘n’)
    b. python 0 1 2 3 4 5
    c. (‘p’, ‘0’)(‘y’, ‘1’)(‘t’, ‘2’)(‘h’, ‘3’)(‘o’, ‘4’)(‘n’, ‘5’)
    d. (0, ‘P’)(1, ‘y’)(2, ‘t’)(3, ‘h’)(4, ‘o’)(5, ‘n’)
  46. What will be the output after the following statements?
    for i in range(1,5):
    print(i, end=”)
    if i == 3:
    break
    a. 123
    b. 1234
    c. 12
    d. 12345
  47. What will be the output after the following statements?
    for i in range(0,5):
    if i == 2:
    break
    print(i, end=”)
    a. 12
    b. 01
    c. 012
    d. 0123
  48. What will be the output after the following statements?
    for i in range(1,5):
    if i == 3:
    continue
    print(i, end=’ ‘)
    a. 1 2 4
    b. 1 2 3 4
    c. 1 2
    d. 1 2 3
  49. What will be the output after the following statements?
    for i in range(0,5):
    print(i, end=”)
    if i == 2:
    continue
    a. 0124
    b. 01234
    c. 12
    d. 1345
  50. What will be the output after the following statements?
    myvar = 5
    def printvar() :
    print(myvar)
    printvar()
    a. 01245
    b. 12345
    c. 5
    d. 1234
SHARE:

Leave a Comment