Computer Science
Write the output of the following:
for x in range(10, 20):
if (x % 2 == 0):
continue
print(x)
Python
Python Control Flow
5 Likes
Answer
19
Working
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.
Answered By
1 Like
Related Questions
Write the output of the following:
for x in range(1, 6): for y in range(1, x+1): print (x, ' ', y)
Write the output of the following:
for x in range(10, 20): if (x == 15): break print(x)
Write the output of the following program on execution if x = 50:
if x > 10: if x > 25: print("ok") if x > 60: print("good") elif x > 40: print("average") else: print("no output")
What are the various ways of creating a list?