I have two values in a list, let's say it's
A = [1, -3]
If the sign of the second value is positive, I can leave the number alone. If the sign of the second value is negative, I need to change the first value to be a -1. But if the first value is a 0, nothin needs to be done at all, since -0 is the same as a positive zero.
So in the case of A, I would need to change 1 to -1. So the final result should be
A = [-1, -3]
I'm a new programmer, so basically all I think is that it involves appending a value to the end of A, and then removing the first value. I think we have to do that because as far as I know, there's no way of just changing the sign of a number.
So, I think it might be something like this:
A = [1, -3]
for i in A:
if #something about the second value being a positive value
pass
else:
A.append("-1")
del A[0]
print A
Any help would be appreciated, thanks!
This works:
if A[1] < 0:
A[0] *= -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With