ComenzarEmpieza gratis

Accessing safely and deleting

Alphabet Inc. was formed in 2015 as part of a corporate restructuring of Google. Analyzing the change in stock prices over time is a common task in the world of finance. One way to store stock data is to use the dates as keys and the prices as values in a dictionary. In this exercise, you access stock closing price data for the company Alphabet for various dates without knowing beforehand if each date has data available. The supplied dictionary alphabet_hist has datetimes as keys and stock closing prices as values. A datetime object named closing_price_date is supplied.

Este ejercicio forma parte del curso

Intermediate Python for Finance

Ver curso

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Closing price for day before
day_before_closing_price_date = closing_price_date - timedelta(days=1)

# Safely print closing price day before or None if it's missing
print(alphabet_hist.____(____))
Editar y ejecutar código