2015-04-26 49 views
0

通常當我爲用戶輸入時,Python會等待,直到他們按下回車鍵。然而,在我的劇本由於某種原因,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運行此。

+4

你的代碼的屏幕截圖是沒有幫助的模擬raw_input()。將您的代碼粘貼到問題中 - 作爲文本。 – Andy

回答

3

問題是在輸入法。 在Python 3.x中raw_input()不存在,只有input()退出。但在舊版本input()raw_input()退出。所以根據你的Python版本使用適當的方法。 See more here.

在Python 3.x中,你可以通過使用eval(input())

+0

撒永說的是真的。自從威廉正在使用3.4並正確輸入(),這不能成爲答案,可以嗎? –

0

在Python,斂輸入的適當的方式是

input = raw_input('prompt')