I am a programming enthusiast with some knowledge on the subject, I beg your pardon, I have a lot to learn, I have this code where I check the balance of my account and receive them in the form of a list and print the currency and the total that I have l side of it, but I print all the values even though I have 0, I was looking for a way to ignore the values in 0 and only print the others and I receive that error, could you help me? thank you very much in advance
my total variable would be returning this: ['18.02787287', '0.00003897', '0.00003067', '0.00002044', '0.0000006', '0', '0', '0', '0', '0']
hence I want it to only print the ones different from 0
coin=[b['currency'] for b in balances]
total=[b['available'] for b in balances]
for i, j in zip(coin, total):
if j>=1:
print('en su cuenta de trade tiene en',i,':', j)
else:
continue
error: '>=' not supported between instances of 'str' and 'int'
Good day,
The problem is because your variable
total
hasstring
the identifiers because each number has quotes, for example'0'
. So when you try to comparej>=1
it tells you that you can't compare astring
with the value1
that is aint
You can convert them
string
to integers (int
) or in your case you would needfloat
because they have decimalsTo do so add
float(j)
in yourif
, like thisif float(j)>=1:
Although if you compare only that it is greater than or equal to 1 then you would be eliminating the values that have decimals, such as
0.0000006