CBSE Class 12 Computer Science Question 62 of 120

Review of Python Basics — Question 14

Back to all questions
14
Question

Question 9(vi)

Write the output of the following:

for x in range(10, 20): 
    if (x % 2 == 0): 
       continue
print(x)
Answer
Output
19
Explanation

In the provided code, a for loop iterates over a range of numbers from 10 to 19. Within the loop, an if statement checks if the current value of x is even (divisible by 2) using the modulo operator '%'. If x is even, the continue statement is executed, causing the loop to skip the rest of the code in that iteration and move to the next iteration. As a result, only odd numbers in the range 10 to 19 will be considered. After the loop completes, the value of x will be the last value of the iteration, which is 19. Therefore, the output of the code will be 19.