[Tutor] Help with "Guess the number" script

Scott W Dunning swdunning at cox.net
Tue Mar 4 03:08:24 CET 2014


On Mar 3, 2014, at 1:51 AM, Ben Finney <ben+python at benfinney.id.au> wrote:
> "Bold” assumes that markup of text will survive; that's not reliable,
> since this is a text-only medium and only the plain text will reliably
> survive to all readers.
Sorry, I didn’t realize.  I’m still new to this.
> 
> You're creating a prompt string, so this is a good choice of name;
> except that its correct spelling is “prompt”.
Haha, I didn’t even catch that, thx.

> This is valuable! Thinking about what the values mean is vital to
> understanding what the program is doing, which is of course a big part
> of what you're in this to learn.
That’s where I’ve been getting the most confused, because the instructor is giving variables he wants used and I was having a hard time figuring out what some of them were doing.  I think I have a better understanding now though.
> 
>> def print_hints(secrets, guess):
>>    secret_number = secret
> 
> You never use this “secret_number” name again, so the binding is
> useless. What was your intention?
I honestly don’t know, I’ve since taken that out completely.
> 
> You also never use the “secrets” parameter; and the “secret” name was
> not bound before you used it. Have you mis-spelled one of those?
> 
>>    guess = guess
> 
> I don't know what the point of this no-op assignment is. What are you
> trying to do?
> 
>>    if guess < 0 or user_guess> 101:
> 
> Likewise, you never bind the name “user_guess”. Where are you expecting
> it to be bound?
That was a mistake.  I’m trying to get it to print “Out of range” if the user guesses a number out of the range of 1-100.  
> 
> 
> I suspect at this point you've been flailing around without much
> understanding of the changes you're making. This leads to a confused
> mass of code that you can't understand or explain.
Yes, correct.
> 
> Better would be to experiment at the interactive Python prompt to test
> what these changes *do*, before putting them into your code. Reduce the
> mechanisms down to very minimal cases, and try them out; confirm your
> assumptions and guesses. Only then should you plan a change to the
> program file.
Ok that makes sense.

Thanks again!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140303/9cab2c88/attachment-0001.html>


More information about the Tutor mailing list