+ 1
can anybody explain the code?
m=0 x=1 while x<5: y=1 while y<4: m=m+y y=y+3 x=x+2 print (m) >>>2 Can anybody explain why out put is 2?
2 Answers
+ 3
x=1
x<5
y=1
y<4
m=1
y=4
x=3
x<5
y=1
y<4
m=2
y=4
x=5
+ 3
To see how it happens, insert print() functions inside the loops, e.g.
m = 0
x = 1
while x < 5:
print("x1", x)
y = 1
while y < 4:
print("y1", y)
print("m1", m)
m = m + y
print("m2", m)
y = y + 3
print("y2", y)
x = x + 2
print("x2", x)
print(m)