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

为何random.randint在Python脚本中无输出?Shell中却正常

问题解答
  • 原因:Python脚本文件中,random.randint(1,25)仅生成了随机整数,但没有执行输出操作;而在交互式Shell环境中,Python会自动打印最后一行表达式的返回值,所以能看到结果。
  • 解决方法:在脚本里用print()函数输出生成的随机数,修改后的代码如下:
import random

print(random.randint(1,25))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 19:10:20