Python:Loop不会等待用户的输入 [英] Python: Loop isn't waiting for user's input

查看:948
本文介绍了Python:Loop不会等待用户的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常当我为用户做输入时,Python会一直等到他们按下回车键。然而,在我的脚本中,出于某种原因,Python不会等待输入并不断输出文本...



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆