a'$'
money=1000000;
portfolio=0;
value=0;
value=(yahoostock.get_price('RIL.BO'));
portfolio=(16*(value));
print id(portfolio);
print id(value);
money= (money-portfolio);
'''
I am getting the error:
Traceback (most recent call last):
File "/home/dee/dee.py", line 12, in <module>
money= (value-portfolio);
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Since money is integer and so is portfolio, I cant solve this problem..anyone can help???
value=(yahoostock.get_price('RIL.BO'));
Apparently returns a string not a number. Convert it to a number:
value=int(yahoostock.get_price('RIL.BO'));
Also the signal-to-noise ratio isn't very high. You've lots of (,), and ; you don't need. You assign variable only to replace them on the next line. You can make your code nicer like so:
money = 1000000
value = int(yahoostock.get_price('RIL.BO'));
portfolio = 16 * value;
print id(portfolio);
print id(value);
money -= portfolio;
money
and portfolio
are apparently strings, so cast them to ints:
money= int( float(money)-float(portfolio) )
As the error message clearly states, both are string, cast with int(var)
.
Note:
Let's see what can we decude from the error message:
portfolio
must be string(str
), which means value
is also a string. Like this:
>>> 16*"a"
'aaaaaaaaaaaaaaaa'
and apparently you missed to post relevant code because the error message tells you that money
is str as well.
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