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)

 

  1. Last line would never be reached.
  2. Get all Questions and Answer from here
  3. You need to have paid subscription to access all questions
  4. 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.

Why Dont you prepare for Python Certifications and Interview Questions with 250+ Questions and Answer : Check Here

Real Exam Number of Questions: 70 Questions
Real Exam Pass Score: 70%
Time Allotted: 90 minutes to complete exam