[Tutor] python problem

bhaaluu bhaaluu at gmail.com
Wed Sep 26 14:12:40 CEST 2007


Greetings Chris,

On 9/25/07, Chris <balderas at whtvcable.com> wrote:
>
>   Ok as I see it, it's should go like this:
>
> Print 'Think of a number between 1 and 100, and let me guess it'
>
> Type1 = input ('Type 1 if I am high')
> Type2 = input ('Type 2 if I am low')
> Type3 = input ('Type 3 if I am dead on')
>
> I can't seem to get the guts of it.  I assume that there are 3 if statements
> and a while statement.
>
> guess
>
> While x !=
>         If guess
>
>
>
> I get lost right around here...help!

Thunk! er, Think! =)
Play the guess-a-number game, and jot down exactly what YOU do
to make a guess.

Prompt:> Think of a number between 1 and 100. Got it?
Prompt:> Okay, now I, the Great Computer, will guess the number...
Prompt:> Is the number 51?
Prompt:> 0=Correct, 1=Lower, 2=Higher: _

The range is 1 to 100. Let's say you think of the number 37.
At he prompt, you type 1 because the number is Lower than 51.
(or whatever scheme you decide to use.)

If you were playing against the computer, and the computer told you
to guess Lower, what would you do? Would you guess 50? 49? 10? 1?
How do you guess when you're playing the game?
How do you narrow it down? Figure it out.

So, now you think you can outsmart the computer half-way through
the game by thinking of a different number, say 38.... Pretty sneaky!
That's like palming the pea in a shell game. Granted, the Great
Computer, isn't very smart... but it IS an idiot savant. It can remember
tons of information that you've forgotten as irrelevant just seconds ago.
So what the Great Computer has been doing, while guessing, is keeping
track of the bounds it can guess between, from the hints you've been
providing [0,1,2, whatever] and maybe even a list of all its guesses that
were not correct. And in a split second, it can compare all that stuff.

Chris, what constraints are you working under? How many Python 'tools'
(keywords, methods, etc.) do you have to solve the problem with?
Input? [raw_inpu(), input(), ...], Output? [print, ...], Selection?
[if, elif, else, ...]
Iteration? [for, while, ...]. You also have to consider what you have
to work with
so far.

-- 
b h a a l u u at g m a i l dot c o m
http://www.geocities.com/ek.bhaaluu/index.html

> import random
> > number = random.randint(1, 101)
> > print "I've thought of a number between 1 and 100."
> > print "Try and guess it!"
> > print
> > guess = input( "What's your guess? ")
> > while guess != number:
> >     if guess > number:
> >         print "Your guess is too high."
> >     else: #elif guess < number:
> >         print "Your guess is too low."
> >     guess = input( "What's your next guess? " ) print
> > "Congratulations! You guessed the number."
> -----Original Message-----
> From: Kent Johnson [mailto:kent37 at tds.net]
> Sent: Tuesday, September 25, 2007 7:32 PM
> To: Chris
> Cc: tutor at python.org
> Subject: Re: [Tutor] python problem
>
> Chris wrote:
>
> > Guess the number from the user using 1,2,3 keys
> >       Ask the user if # is high, low, or dead on.
> >               Print 'you got it' when Python gets it.
> >
> > As you can see I need help. I've given you the pseudo code.
>
> OK, how about some real code? If we write the program for you that won't
> help you learn. What have you tried so far? Which parts of the
> pseudocode do you know how to code? Which parts do you need help with?
>
> Kent
>
>
>
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.487 / Virus Database: 269.13.25/1018 - Release Date: 9/19/2007
> 3:59 PM
>
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.487 / Virus Database: 269.13.25/1018 - Release Date: 9/19/2007
> 3:59 PM
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list