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

Python数据加载模拟程序循环打印异常问题求助

问题修复方案

你的代码问题在于print("yo files crashed again")被缩进在了for循环内部,导致每次循环都会执行这个打印操作,所以会重复输出3次。

修复后的代码如下:

import time

var = {
 "SFRSGSSCE",
 "ndbnwmmwq"
}

print("Files are here")

print("Loading")
for i in range(3):
 time.sleep(2)
 print(".")

print(var)
print("The files crashed.")

print("If you want to try again, say yes.")
putin = input('>>>')

if putin.lower() == "yes":
 print("Loading")
 for i in range(3):
  time.sleep(2)
  print(".")
 # 把崩溃提示移到循环外面,只执行一次
 print("yo files crashed again")
  
else:
 print("ok im unemployed....")

修改说明:将print("yo files crashed again")的缩进级别降低,放到for循环的外部。这样当3次加载点打印完成后,才会执行一次崩溃提示,符合你的预期逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.02 05:12:33