Python:Loop不会等待用户的输入 [英] Python: Loop isn't waiting for user's input
问题描述
user_option()
,里面只有几个打印语句...
如果有人能告诉我如何制作它,它会等待,直到用户输入一个输入这将非常赞赏。
代码:
while True :
user_option()
decision = input(我应该采取什么粗糙行动?)
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版本使用适当的方法。 在这里查看更多。
在Python 3.x中,您可以使用 eval(input())模拟
raw_input()
)
Normally when I do a input for the user, Python waits until they press the enter key. However in my script for some reason Python isn't waiting for an input and keeps printing the text...
user_option()
, just has a few print statements in it...
If anyone could tell me how to make it so it will wait until the user enters an input that would be very much appreciated.
Code:
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()
I'm running this with Python 3.4.
Problem is in the input method. In Python 3.x raw_input()
does not exits and only input()
exits. But in older version input()
and raw_input()
exits. So according to your Python version use proper method. See more here.
In Python 3.x you can simulate raw_input()
by using eval(input())
这篇关于Python:Loop不会等待用户的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!