执行后,input()
提示符将打印在其上方的print()
之前。
执行的结果是打印
Color1:Guess the code
我正在使用顶篷编辑器。我尝试了
guess[x]=input("Color %s:") % str(x+1)
和guess[x]=input("Color"+str(x+1))
guess=[None]*n
print("Guess the code")
for x in range(5):
tempstring = "Color"+str(x+1)+":"
guess[x]=input(tempstring)
我希望输出是
Guess the code
Color1:
然后允许用户输入字母
最佳答案
当我复制并运行此代码时,它可以按预期工作。
对我来说,这似乎是一个冲洗问题。您是否可以尝试在打印功能中使用flush=True
强制刷新,如下所示:
print("Guess the code", flush=True)
关于python - 为什么python似乎无法按顺序执行代码?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58223233/