Reputation: 21
Why the output for the below prog is [6.2202, 'aboy', False, 87]
and not [6.2202, 'aboy', False, 641]
L=[2e-04, 'a', False, 87]
T=[6.22, 'boy', True, 554]
for i in range(len(L)):
if L[i]:
L[i] = L[i] + T[i]
else:
T[i] = L[i] + T[i]
break
print(L)
Upvotes: 1
Views: 82
Reputation: 13413
The break
statement in the else
clause causes the loop to stop,
so after the first time the condition is false - no following iterations will happen
(Of course for i==2
you get L[i] == False
so you enter the else
clause and the loop never executes for i==3
with the values 87
and 554
)
Upvotes: 1