[Tutor] i am stuck...
Ian Witham
witham.ian at gmail.com
Thu Sep 27 07:05:25 CEST 2007
On 9/27/07, Ian Witham <witham.ian at gmail.com> wrote:
>
> On 9/27/07, Chris <balderas at whtvcable.com> 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.
>
Some Pseudocode might help:
secret_number = something
bottom = 1
top = 101
guess = 50
while guess != secret number:
print "My guess is: ___"
if guess too low:
print "That guess is too low."
bottom = guess
if guess too high:
print "That guess is too high."
top = guess
guess = make a new guess, halfway between top and bottom
print "I have guessed your number, it is ____"
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070927/b85e661a/attachment-0001.htm
More information about the Tutor
mailing list