[Tutor] Help with "Guess the number" script
Ben Finney
ben+python at benfinney.id.au
Mon Mar 3 09:51:35 CET 2014
Scott W Dunning <swdunning at cox.net> writes:
> This is what Im having trouble with now. Here are the directions I’m
> stuck on and what I have so far, I’ll bold the part that’s dealing
> with the instructions if anyone could help me figure out where I’m
> going wrong.
“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.
Instead, explain what is confusing you, and if you need to show someone
else's words, use the plain-text quotation.
> def get_guess(guess_number):
> promt = "(" + str(guess_number) +") Please enter a guess:"
You're creating a prompt string, so this is a good choice of name;
except that its correct spelling is “prompt”.
> user_guess = raw_input(promt)
> user_guess = int(user_guess)
These are two separate values, why are you binding one name and then
immediately re-binding the same name to a different value?
Have a think about what each intermediate value *means*, and choose
names on that basis.
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.
> 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?
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?
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.
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.
--
\ “I must have a prodigious quantity of mind; it takes me as much |
`\ as a week sometimes to make it up.” —Mark Twain, _The Innocents |
_o__) Abroad_ |
Ben Finney
More information about the Tutor
mailing list