CBSE Class 12 Computer Science Question 61 of 120

Review of Python Basics — Question 13

Back to all questions
13
Question

Question 9(v)

Write the output of the following:

for x in range(10, 20): 
    if (x == 15):
        break
print(x)
Answer
Output
15
Explanation

The code sets up a for loop that iterates over a range of numbers from 10 to 19. During each iteration, the variable x takes on these values sequentially. Within the loop, an if statement checks if x is equal to 15. When x reaches 15, the condition is met, and the break statement is executed, immediately exiting the loop. As a result, the loop terminates prematurely, and the value of x at the point of exit, which is 15, is printed.