Python IDLE 2.7在我按“回车”之前不执行文件

3 投票
1 回答
654 浏览
提问于 2025-04-17 18:11

有一个奇怪的情况,当我选择“运行模块”时,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)

非常感谢!

1 个回答

1

可以查看这个链接:http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/execution.html(看一下1.9.2这一部分)。这是一个有时会出现的错误,通常是因为之前的程序被中断了。

撰写回答