2013-03-06 82 views
3

由於某些原因,當我選擇「運行模塊」時,IDLE將不會運行第一行代碼,直到按下「enter」。這種類型的程序不是一個大問題,但我很困惑爲什麼會發生這種情況。任何人都可以爲我解決這個問題嗎?下面的代碼:Python IDLE 2.7將不會執行文件,直到我點擊「enter」

print("Please think a number between 0 and 100!") 
guess = 50 
upper = 100 
lower = 0 
status = "" 
while status != "c": 
    print("Is your secret number ") + str(guess) + ("?") 
    print ("Lower: ") + str(lower) 
    print ("Upper: ") + str(upper) 
    status = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate  the guess is too low. Enter 'c' to indicate I guessed correctly. ") 
    if status == "h": 
     upper = guess 
     guess = guess - (guess - lower)/2 
    elif status == "l": 
     lower = guess 
     guess = guess + (upper - guess)/2 
    elif status == "c": 
     break 
    else: 
    print("Sorry, I did not understand your input.") 
print("Game over. Your secret number was: ") + str(guess) 

非常感謝!

+0

在某些平臺/版本上,如果模塊自上次保存後編輯完畢,「運行前保存或檢查」對話框有時會彈出另一個窗口。它仍然是活動的,所以當你點擊「enter」觸發「確定」按鈕,但你沒有看到它。這可能是你的情況嗎? (我已經在OS X 10.6上看到了這個,python.org Python 2.6,但是Apple Tk。唯一的解決方法是使用Apple的Python或者安裝ActiveState Tk,就像python.org的下載頁面所解釋的那樣。發生在那裏,它可能發生在其他平臺上。) – abarnert 2013-03-06 22:10:18

回答

相關問題