Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python IDLE 2.7 won't execute file until I hit "enter"

For some reason when I select "run module", IDLE won't run the first line of code until I press "enter". It's not a huge problem for this type of program, but I'm confused why this is happening. Can anyone clear this up for me? Here's the code:

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)

Thanks so much!

like image 455
jtimmins Avatar asked Jul 29 '26 16:07

jtimmins


1 Answers

See http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/execution.html (see section 1.9.2). It's a bug that occurs sometimes if the previous program was interrupted.

like image 125
Groditz Avatar answered Aug 01 '26 08:08

Groditz