Advertisements
Advertisements
प्रश्न
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)टिप्पणी लिखिए
Advertisements
उत्तर
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
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
