Contents

What will be the output of the following Python code?
a) 1                                                        
b) 1 2
c) 1 2 3 4 5 6 …  
d) 1 3 5 7 9 11 …

d

Explanation: The loop does not terminate since i is never an even number.


What will be the output of the following Python code?
a) 2 4 6 8 10 …   
b) 2 4
c) 2 3                                     
d) error

b

Explanation: The numbers 2 and 4 are printed. The next value of i is 6 which is divisible by 3 and hence control exits the loop.


What will be the output of the following Python code?
a) 1                                                        
b) 1 3 5 7 …
c) 1 2 3 4 …                         
d) none of these

d

Explanation: Control does not enter the loop because of False.


What will be the output of the following Python code?
a) True                                  
b) False
c) None                                 
d) none of these

d

Explanation: SyntaxError, True is a keyword and it’s value cannot be changed.


What will be the output of the following Python code?
a) 0 1 2 0                                              
b) 0 1 2
c) error                                  
d) none of these

b

Explanation: The else part is not executed if control breaks out of the loop.


What will be the output of the following Python code?
a) 0 1 2 3 0                           
b) 0 1 2 0
c) 0 1 2                                  
d) error

b

Explanation: The else part is executed when the condition in the while statement is false.