Quiz: Python Part-1

To View Tricks: Login Required

Number of Questions: 37

Question: 31 -

Study the following program:

 

i = 0  

while i < 5:  

    print(i)  

    i += 1  

    if i == 3:  

        break  

else:  

    print(0)  

What will be the output of this statement?

Options:
  1. 0 1 2

  2. 3 2 1

  3. 1 2 3

  4. 0 1 2 3

  5. Answer:

    0 1 2

    Solution not available.

Question: 32 -

Study the following program:

i = 1:  

while True:  

    if i%3 == 0:  

        break  

    print(i)  

Which of the following is the correct output of this program?

Options:
  1. 3 2 1

  2. Invalid Syntax

  3. 1 2 3

  4. Answer:

    Invalid Syntax

    Solution:

    Invalid syntax, because this declaration (i = 1:) is wrong.


Question: 33 -

Study the following program:

i = 0  

while i < 3:  

    print(i)  

    i += 1  

else:  

    print(0)  

What will be the output of this statement?

Options:
  1. 0 1 2

  2. 0 1 2 3

  3. 0 1 2 0

     

  4. 0 1

  5. Answer:

    0 1 2 0

     

    Solution not available.

Question: 34 -

Study the following program:

a = 1  

while True:  

    if a % 7 = = 0:  

        break  

    print(a)  

    a += 1  

Which of the following is correct output of this program?

Options:
  1. Invalid syntax

  2. 1 2 3 4 5 6 7

  3. 1 2 3 4 5

  4. 1 2 3 4 5 6

  5. Answer:

    1 2 3 4 5 6

    Solution not available.

Question: 35 -

Study the following program:

x = ['xy', 'yz']  

for i in a:  

    i.upper()  

print(a)  

Which of the following is correct output of this program?

Options:
  1. ['xy', 'yz']

  2. ['XY', 'YZ']

  3. [None, None]

  4. None of these

  5. Answer:

    ['xy', 'yz']

    Solution not available.