ProgrammingHardAccenture · Cognizant · Python

What does the following Python 3 code print? x = 1 while x < 5: x += 1 if x == 3: break else: print("no-break") print(x)

  1. A. no-break 3
  2. B. 3
  3. C. no-break 5
  4. D. 5

Correct answer: B. 3

x increments to 2 then 3, and break fires immediately at x==3, skipping the else clause; the final print shows x==3.

More Python Programming questions

Exams that ask this topic