Jan-26-2022, 03:59 PM
Hello,
I am trying to understand what is going on:
Thank you
I am trying to understand what is going on:
class Portfolio: def __int__(self): self.holdings = {} #key = ticker, Value = number of shares def buy(self, ticker, shares): self.holdings[ticker] = self.holdings.get(ticker, 0) + shares def sell(self, ticker, shares): self.holdings[ticker] = self.holdings.get(ticker, 0) - shares def __iter__(self): return iter(self.holdings.items()) p = Portfolio() p.buy('Alpha', 15) p.buy('Beta', 23) p.buy('Gamma', 9) p.buy('Gamma', 20) p.sell('Beta', 5) for (ticker, shares) in p: print(ticker, shares)According to the errors output:
Error:Traceback (most recent call last):
File "<string>", line 19, in <module>
File "<string>", line 9, in buy
AttributeError: 'Portfolio' object has no attribute 'holdings'
>
I am missing a module? But which one?Thank you