Question-102: What would happen, when you run below program?
n = 0
while n < 5:
print(n)
n += 1
else:
print("Is this else block ever executed", n)
- Last line would never be reached.
- Get all Questions and Answer from here
- You need to have paid subscription to access all questions
- Thanks for considering Python Certification Material
Answer: B
Exp: In this case n starts with 0 and until it become 4 it iterates and print its value. Hence, total 5 lines. And once n become 5 it would run else block once. Hence, 1 more line would be printed.
You can access to full explanation to question and answer from this page.