Python Questions and Answers – While and For Loops – 2
This set of Advanced Python Questions & Answers focuses on “While and For Loops”.
1. What is the output of the following?
a) 0 1 2 0
b) 0 1 2
c) error
d) none of the mentioned
View Answer
b) 0 1 2
c) error
d) none of the mentioned
View Answer
Answer: b
Explanation: The else part is not executed if control breaks out of the loop.
Explanation: The else part is not executed if control breaks out of the loop.
2. What is the output of the following?
a) 0 1 2 3 0
b) 0 1 2 0
c) 0 1 2
c) error
View Answer
b) 0 1 2 0
c) 0 1 2
c) error
View Answer
Answer: b
Explanation: The else part is executed when the condition in the while statement is false.
Explanation: The else part is executed when the condition in the while statement is false.
3. What is the output of the following?
a) a b c d e f
b) abcdef
c) i i i i i i …
d) error
View Answer
b) abcdef
c) i i i i i i …
d) error
View Answer
Answer: d
Explanation: NameError, i is not defined.
Explanation: NameError, i is not defined.
4. What is the output of the following?
No comments:
Post a Comment