首页 > 解决方案 > 代码没有为决策函数返回正确的结果

问题描述

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

当预期输出为 Buy 2 Shares 时,代码返回“Hold Shares”。

 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"

标签: python

解决方案


推荐阅读