On 9/27/07, Chris <[EMAIL PROTECTED]> wrote:
>
> I don't know what to do at this point.  I do not have the book, but will
> get
> it just to have...
>
> Can anyone help me?
>
> > Here some more work:
> >
> >
> > guess = 0
> >
> > Print ?Pick a number between 0 and 100?
> >
> >
> > While guess != ________ :
> >       print ?My first guess is ?, guess
> >       print ?Is my guess correct??
> >       if guess = = type3
> >               print ?I got it!?
> >       if guess > _______:
> >               pick lower #
> >       if guess <_______ :
> >               pick higher #
> >
> > that?s all I can do right now?
> >
> > the mechanism that I can?t figure out is how to show in code form how
> the
> > computer goes to the next guess using the split range... ie. if the
> first
> > guess is 50, the second guess would be taken from the 50-100 (50/2 = 25
> +
> 50 = 75) second guess  would be 75 if the number is too high.  If the
> number
> > falls below 50, then the split range is 25, ect?



Try having these 3 variables:

top, the top number that the secret number might be.
bottom, the lowest number that the secret number might be.
guess, the current guess.

if the guess is too high, then the value for guess should become your new
'top':
if guess > secret_number:
    top = guess

If the guess is too low, do the opposite. 'bottom' should now be set to
guess

Now create a new value for guess using your new values for top and bottom,
and guess again.

Ian.
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to