python - 为什么 python 执行代码看起来是乱序的?

标签 python

执行时,input()提示符打印在 print() 之前它上面。 执行结果打印

Color1:Guess the code

我正在使用 Canopy 编辑器。我已经尝试过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/

相关文章:

python - SSL 传输上的异步 fatal error - IndexError Deque 索引超出范围

python - 通过python从响应数据中检索特定数据

javascript - Flask 返回重定向在删除后不起作用

python - 为什么 'x += y' 并不总是与 Python (2.7) 中的 'x = x + y' 相同?

python - Scikit-learn 的 Pipeline : Error with multilabel classification. 传递了一个稀疏矩阵

python - cx_freeze : How do I resolve conflicts caused by multiple . 同名dylib文件

python - 使用 Tkinter 快速制作圆日志

python - 将 ubuntu 15.10 升级到 16.04 后 virtualenv python 崩溃了

python - O365 EO 可恢复项目文件夹的 REST Api

python - VSCode PyLint 未检测到我的 Python DTO 类成员