Question
class Stock: def __init__(self, company_name, ticker, trading_price, num_shares): Question 1a Complete the __init__ method by passing in parameters and assign the parameters to the
class Stock:
def __init__(self, company_name, ticker, trading_price, num_shares): """ Question 1a Complete the __init__ method by passing in parameters and assign the parameters to the corresponding attributes. __init__ should take in the full company name, ticker, trading price, and the number of existing shares.
Example: >>> stonk = Stock("Gamestop Corp", "GME", 325.00, 480000) """ pass
def __eq__(self, other): """ Question 1b Complete the __eq__ method. Two Stocks objects are equal if and only if they share the same ticker and same market cap (trading price * number of existing shares).
Example: >>> stonk1 = Stock("Nokia", "NOK", 100.00, 23000) >>> stonk2 = Stock("Nooookia", "NOK", 100.00, 23000) >>> stonk1 == stonk2 True """ pass
def __lt__(self, other): """ Question 1c Complete the __lt__ method. A Stock object is less than another if its market cap (trading price * number of existing shares) is lower.
Example: >>> stonk1 = Stock("S&P 500", "SPY", 150.00, 150000) >>> stonk2 = Stock("NASDAQ", "QQQ", 200.00, 190000) >>> stonk1 < stonk2 True """ pass
def __repr__(self): """ Question 1d Complete the __repr__ method. Calling or printing a Stock object should be represented as the following string: <{ticker}: ${trading_price}, {num_shares}>
Example: >>> stonk = Stock("Blackberry", "BB", 45.00, 12000) >>> stonk
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started