You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python函数number_inclusion无法返回list[int]的问题排查与解决

多模式骰子投掷程序Selective模式ValueError问题解决

问题现象

开发多模式骰子投掷程序的Selective模式时,遇到以下异常情况:

  • 自定义函数 number_inclusion() 设计目标是返回 list[int],并将结果添加到 user_input() 函数内的 included_numbers 列表中
  • 执行review操作时,列表内容显示正常,但函数执行完成后会触发 user_input() 中try-except块的 ValueError,错误提示为:Only numbers accepted

修复步骤

通过排查代码,最终通过两处修改解决了问题:

  • 移除 number_inclusion() 函数末尾冗余的else代码块
  • 将 user_input() 中用于添加列表元素的 append 方法替换为 extend 方法

内容的提问来源于stack exchange,提问作者Zachiel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 21:10:30