0
Why does it give 6?
A=[8,0,-4,-6,1] for n in A: if n<0: A.append(abs(n)) print(n)
3 Réponses
+ 4
Because you are printing n after the end of the for loop.
n will be equal to the last element in the A list wich is the last element you have append (abs(-6))
Note that A will be equal to [8,0,-4,-6,1,4,6] when the loop is end.
+ 1
The code in the for loop appends 4 and 6 to A. That makes 6 the last value in A and after the last iteration of the loop n is the last value in the A.
Also:
https://code.sololearn.com/W3uiji9X28C1/?ref=app