Write me python code that gets the stock price of MSFT using yfinance.
- User
Write me python code that gets the stock price of MSFT using yfinance.
Assistant
Sure, here's some Python code that uses the
yfinancelibrary to retrieve the stock price of Microsoft (MSFT):import yfinance as yf # Set the symbol for the stock symbol = 'MSFT' # Get the stock information stock = yf.Ticker(symbol) # Print the current price of the stock print(stock.current)This code first imports the
yfinancelibrary and sets the symbol for the stock to be retrieved to 'MSFT'. Then, it uses theyf.Ticker()method to retrieve the stock information and assigns it to the variablestock. Finally, it prints the current price of the stock by accessing thecurrentattribute of thestockobject.Note that this code assumes that you have already installed the
yfinancelibrary and imported it usingpip install yfinance.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.