代码没有为决策功能返回正确的结果

时间:2019-09-18 02:57:57

标签: python

当给定输入为当前价格= 1且投资为12时,我遇到了问题

当预期输出为“买入2股”时,代码将返回“持股”。

 def trade_action(current_stock, purchase_price, current_price, investment,):
 # Write your code here.
    if current_price<purchase_price:
        investment-=10
        number_shares = investment/current_price
        profits= (number_shares*current_price-purchase_price)-10
        if profits >= 0:
            return "Buy", int (number_shares)
        else:
            return "Hold Shares"
    elif current_price> purchase_price:
        if current_price-purchase_price*current_stock-10>0:
            return "Sell Shares", int (number_shares)
        else: 
            return "Hold Shares"
    else:
        return "Hold Shares"

0 个答案:

没有答案