-2
I’m having trouble solving this error:
Valueerror: Too Many values to unpack (expected 3)
This is my code:
def func(array, n):
m = len(array)
soma = 0
saldo = []
res = 0
bool = False
saldo = [0 for i in range(n+1)]
for i in range(m):
x, v, y = [x for x in range(n)] # **O erro está nessa linha**
saldo[x] += v
saldo[y] += v
soma += v
for i in range(1, n+1):
if saldo[i] > 0:
#res.append(saldo[i])
res += saldo[i]
elif saldo[i] < 0:
#res.append(-saldo[i])
res += -saldo[i]
if res == soma:
bool = False
else:
bool = True
return bool, res
print(func([[3,1,10],[2,1,40],[2,4,30],[2,4,20]], 4))
Thank you in advance ;)
You have four elements in the list to unpack and only three variables to receive these elements. One element remains.
– Augusto Vasques
Perhaps it is better to explain what the code should do (what should be the result: given the values A and B, it should return X ey, etc.). Suddenly the solution doesn’t even need unpacking...
– hkotsubo