Quiz : pass, continue, break, and else in Python

Quiz: pass, continue, break, and else in Python

Quiz: Loop Manipulation using pass, continue, break and else in Python

15 multiple-choice questions. Choose the best option. Click Submit to see your score and explanations. Use Reset to try again.

1. What does the pass statement do inside a loop?
2. Which statement skips the current iteration and moves to the next?
3. What happens when break is executed in a loop?
4. When will the else clause after a for loop execute?
5. Consider this code: for i in range(3): if i==1: pass print(i) else: print('Done') — What prints?
6. Which of the following is TRUE about pass?
7. What will the following code print?
for n in [1,2,3]: if n==2: break else: print('No break')
8. Which statement best describes the interaction of continue with the loop else?
9. Consider:
i = 0 while i < 3: i += 1 if i == 2: continue print(i) else: print('Done') — What is output?
10. Which is the correct reason to use pass?
11. What will this print?
for x in range(2): for y in range(2): if x==1 and y==0: break else: print('Inner else') else: print('Outer else')
12. Can break be used inside a try/except block within a loop?
13. Which is the result of using continue inside a nested loop?
14. What does this code print?
for i in []: pass else: print('Empty')
15. In which scenario will loop else NOT run?

Comments

Popular posts from this blog

Topic1 :- What is Python Programming?

Topic2: -Why Python?

Topic7: What is Numpy?