Home / CSE MCQs / Python MCQs :: Python While and For Loops

CSE MCQs :: Python MCQs

  1. What is the output of the following?

    i = 2
    while True:
        if i%3 == 0:
            break
        print(i)
        i += 2
  2. A.
    2 4 6 8 10 "¦
    B.
    2 4
    C.
    2 3
    D.
    error

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What is the output of the following?

    x = "abcdef"
    i = "a"
    while i in x:
        x = x[:-1]
        print(i, end = " ")
  4. A.
    i i i i i i
    B.
    a a a a a a
    C.
    a a a a a
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What is the output of the following?

    x = "abcdef"
    i = "i"
    while i in x:
        print(i, end=" ")
  6. A.
    no output
    B.
    i i i i i i "¦
    C.
    a b c d e f
    D.
    abcdef

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What is the output of the following?

    x = 'abcd'
    for i in x:
        print(i.upper())
  8. A.
    a b c d
    B.
    A B C D
    C.
    a B C D
    D.
    error

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What is the output of the following?

    x = 'abcd'
    for i in range(len(x)):
        x[i].upper()
    print (x)
  10. A.
    abcd
    B.
    ABCD
    C.
    error
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What is the output of the following?

    d = {0: 'a', 1: 'b', 2: 'c'}
    for x in d.values():
        print(x)
  12. A.
    0 1 2
    B.
    a b c
    C.
    0 a 1 b 2 c
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What is the output of the following?

    d = {0: 'a', 1: 'b', 2: 'c'}
    for x in d.keys():
        print(d[x])
  14. A.
    0 1 2
    B.
    a b c
    C.
    0 a 1 b 2 c
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What is the output of the following?

    for i in range(float('inf')):
        print (i)
  16. A.
    0.0 0.1 0.2 0.3 "¦
    B.
    0 1 2 3 "¦
    C.
    0.0 1.0 2.0 3.0 "¦
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. What is the output of the following?

    string = "my name is x"
    for i in string.split():
        print (i, end=", ")

  18. A.
    m, y, , n, a, m, e, , i, s, , x,
    B.
    m, y, , n, a, m, e, , i, s, , x
    C.
    my, name, is, x
    D.
    error

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. What is the output of the following?

    a = [0, 1, 2, 3]
    for a[0] in a:
        print(a[0])
  20. A.
    0 1 2 3
    B.
    0 1 2 2
    C.
    3 3 3 3
    D.
    error

    View Answer

    Workspace

    Discuss Discuss in Forum