Jan-27-2022, 04:47 PM
(This post was last modified: Jan-27-2022, 05:16 PM by deanhystad.)
The thing that was missing was the second "i" in "__init__()". Your Portfolio class did not have an __init__() method because you made a mistake when typing the method name. Instead you wrote a __int__() method which was never used.
When you created a Portfolio object Python looked to see if the Portfolio class has an __init__() method. It did not because of your typing error. This resulted in the holdings dictionary never being created.
What is your question about this code?
When you created a Portfolio object Python looked to see if the Portfolio class has an __init__() method. It did not because of your typing error. This resulted in the holdings dictionary never being created.
What is your question about this code?
for (ticker, shares) in p: print(ticker, shares)If you fix the typing error in the Portfolio.__init__() method name the loop will work. If you don't fix the method name your program never reaches this point in the code because it crashes when you call Portfolio.buy().