python - 代码没有为决策函数返回正确的结果
问题描述
当给定的输入是当前价格 = 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 - 模块“xml.dom”没有属性“节点”
- java - 如何使用外部 java 库在命令行中编译和运行 kotlin 程序
- mysql - 如何让这个 MySQL 查询运行得更快?
- c# - C# DataGridview 与单元格事件中的条件
- python - Django过滤器 - 按相关模型中字段的平均值过滤
- c - 接近初始化结构警告
- python - Django文件上传中/files/的MultiValueDictKeyError
- python - 生成整数序列的完整排列
- javascript - 在 2 个 JS 应用程序之间同步事件
- android - 使用 sharedpreference 保存复选框值问题