Jul-24-2017, 02:54 PM
(This post was last modified: Jul-24-2017, 02:55 PM by ichabod801.)
The problem you have here is you are not keeping the new values. Each time through the loop you assign guess to the correct new_max or new_min, but then you overwrite the other one with the original value. Say the target is 81, and you guess 50, which is too low. You set new_min to 50 and new_max to 100. Then, say you guess 90, which is too high. You set new_max to 90 (good) but then resent new_min back to 1 (bad).
There are two ways to fix this. One is to remove
There are two ways to fix this. One is to remove
new_max = maximum
and new_min = minimum
. Of course, this will give you a NameError, because the first time through the loop they will not have been assigned yet. So just before the loop, initialize those variables:new_max = maximum new_min = minimumThe other solution would be to get rid of new_max and new_min, and to just modify maximum and minimum directly. So after a low guess, you would have
minimum = guess
and after a high guess you would have maximum = guess
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures