Get startedGet started for free

Negating with Boolean operators

It is often the case that you need to combine Boolean operations to solve more complicated problems. Let's say that you need to know if you need to download the closing stock prices for today. You only want to do the operation if the markets have already closed. The closing prices are a list held in the provided variable closing_prices. The supplied variable market_closed is set to True once the markets close. Use Boolean operations and what you know about how objects evaluate in them to determine if you should download the data.

This exercise is part of the course

Intermediate Python for Finance

View Course

Exercise instructions

  • Set the variable not_prices to True if you do not have closing prices for today.
  • Set the variable get_prices to True if the market is closed and you don't have closing prices yet.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

print(closing_prices)

# Assigning True if we need to get the prices
not_prices = ____ closing_prices

print(not_prices)

# Get prices if market is closed and we don't have prices
get_prices = ____ (market_closed ____ not_prices)

print(get_prices)
Edit and Run Code