Witam, skleciłem taki kod do bisection search w pythonie
l=0;
h=100;
guess=50;
ans=raw_input('Input a number from <0-100>');
print('Is your secret number ' + str(guess) + '? ')
ans=raw_input('Input h if number is too high, l if too low and c if correct');
while ans!="c":
if ans =="h":
guess=(guess+l)/2
print('Is your secret number ' + str(guess) + '? ')
ans=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. ')
elif ans=="l":
guess=(guess+h)/2
print('Is your secret number ' + str(guess) + '? ')
ans=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. ')
elif not(ans in["l","h"]):
print('Sorry, I did not understand your input.')
print('Is your secret number ' + str(guess) + '? ')
ans=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.')
print "Game over. Your secret number was: "+str(guess)
Program wpada w nieskonczoną pętle, jak to naprawić? Jest to taka zgadywanka, user wpisuje liczbe i program ma zadanie zgadnąć.
<code=python>kod</code>
)