3

出于某种原因,当我选择“运行模块”时,IDLE 不会运行第一行代码,直到我按“回车”。对于这种类型的程序来说,这不是一个大问题,但我很困惑为什么会这样。谁能帮我解决这个问题?这是代码:

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)

非常感谢!

4

1 回答 1

1

参见http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/execution.html(参见第 1.9.2 节)。如果先前的程序被中断,有时会发生此错误。

于 2013-03-06T22:43:26.567 回答