Advertisements
Advertisements
Question
Find the output of the following program segment:
for x in range(1,4):
for y in range(2,5):
if x * y > 10:
break
print (x * y)Short/Brief Note
Advertisements
Solution
The first loop will iterate over the list [1, 2, 3]
The second for loop will iterate over the list [2, 3, 4]
The print statement is printing the value of x * y i.e. [1*2, 1*3, 1*4, 2*2, 2*3, 2*4, 3*2, 3*3, 3*4] which comes out to be [2, 3, 4, 4, 6, 8, 6, 9, 12].
The break statement will terminate the loop once the value of x * y is greater than 10, hence, the output value will be till 9.
OUTPUT:
2
3
4
4
6
8
6
9
shaalaa.com
Is there an error in this question or solution?
