Computer Science
Predict the output of the following code fragments:
for x in range(3):
for y in range(4):
print (x, y, x + y)
Python
Python Control Flow
16 Likes
Answer
0 0 0
0 1 1
0 2 2
0 3 3
1 0 1
1 1 2
1 2 3
1 3 4
2 0 2
2 1 3
2 2 4
2 3 5
Working
For each iteration of outer loop, the inner loop executes four times (with value of y ranging from 0 to 3) generating this output.
Answered By
5 Likes
Related Questions
Predict the output of the following code fragments:
x = 10 y = 5 for i in range(x-y * 2): print (" % ", i)
Predict the output of the following code fragments:
for x in [1,2,3]: for y in [4, 5, 6]: print (x, y)
Predict the output of the following code fragments:
c = 0 for x in range(10): for y in range(5): c += 1 print (c)
What is the output of the following code?
for i in range(4): for j in range(5): if i + 1 == j or j + 1 == 4: print ("+", end = ' ') else: print ("o", end = ' ') print()