gpt4 book ai didi

Python:循环不等待用户的输入

转载 作者:太空宇宙 更新时间:2023-11-04 08:06:46 29 4
gpt4 key购买 nike

通常当我为用户进行输入时,Python 会等待直到他们按下回车键。但是在我的脚本中,出于某种原因,Python 没有等待输入并继续打印文本...

user_option(),里面只有一些打印语句...

如果有人能告诉我如何制作它,那么它会等到用户输入一个非常感谢的输入。

代码:

while True:
user_option()
decision = input("What coarse of action should I take?")
decision = decision.strip().lower()
if decision == "a":
rehydration()
elif decision == "b":
moderate_speed()
elif decision == "c":
fast_speed()
elif decision == "d":
rest()

我正在使用 Python 3.4 运行它。

最佳答案

问题出在输入法上。 在 Python 3.x 中 raw_input() 不退出,只有 input() 退出。 但在旧版本中 input()raw_input() 退出。所以根据你的 Python 版本使用适当的方法。 See more here.

在 Python 3.x 中,您可以使用 eval(input()) 模拟 raw_input()

关于Python:循环不等待用户的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29873602/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com