+ 1
Why the right answer of the code showed in the description is 6 (I take it from a challenge)
What is the output of this code? A = [8, 0, -4, -6, 1] for n in A: if n < 0: A.append(abs(n)) x = n print(x)
2 Answers
+ 5
n = 8
n < 0 False
.
.
.
n = -4
n < 0 True
A becomes [8, 0, -4, -6, 1, 4]
n = -6
n < 0 True
A becomes [8, 0, -4, -6, 1, 4, 6]
Then there are no more negative values, the last value of A Is 6, so x = 6
+ 1
Thanks man I got it :)