開始使用免費開始

使用布林運算做決策

在 Python 中,布林運算用來做決策。想像你是分析師,需要找出可能會進行股票交易的帳戶。你可以用這些資訊來建議符合條件的客戶採取市場行動。 已提供變數 is_investment_account。若該帳戶的持有部位包含股票部位,則其值為 True。已提供的變數 balance_positive 在帳戶現金餘額為正(可用來購買有價證券)時為 True

本練習屬於課程

Intermediate Python for Finance

檢視課程

練習說明

  • 列印變數 balance_positive 的值。
  • 如果該帳戶是投資帳戶且餘額為正,將變數 potential_trade 設為 True
  • 如果是潛在交易,列印 True

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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(____)
編輯並執行程式碼