MulaiMulai sekarang secara gratis

Decisions with Boolean operations

Boolean operations are used in Python to make decisions. Imagine that you work as an analyst identifying accounts that might potentially participate in stock trades. You might use this information to advise qualifying clients on market moves. The variable is_investment_account is supplied. It is set to True if the given account includes stock positions as part of it's holdings. The supplied variable balance_positive is set to True if the account has a positive cash balance, which could be used to purchase securities.

Latihan ini adalah bagian dari kursus

Intermediate Python for Finance

Lihat Kursus

Petunjuk latihan

  • Print the value of the variable balance_positive.
  • Set the variable potential_trade to True if the account is an investment account with a positive balance.
  • Print the True if this is a potential trade.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Print the given variables
print(is_investment_account)
print(____)

# Decide if this account is cantidate for trading advice
potential_trade = is_investment_account ____ balance_positive

# Print if this represents a potential trade
print(____)
Edit dan Jalankan Kode