[Tutor] Help with "Guess the number" script

Dave Angel davea at davea.name
Sun Mar 2 13:37:49 CET 2014


 Scott W Dunning <swdunning at cox.net> Wrote in message:
> 
> On Mar 1, 2014, at 12:47 AM, Ben Finney <ben+python at benfinney.id.au> wrote:
> 
>> You've bound the name ‘current_guess’ to the user's input, but then do
>> nothing with it for the rest of the function; it will be discarded
>> without being used.
> Hmm, I’m not quite sure I understand.  I got somewhat confused because the directions were changed a little and current_guess was removed from the get_guess function.  Is this more like what I should be doing?
> 
> def get_guess(guess_number):
> 	raw_input(“Please enter a guess”)
> 	guess_number = int(guess_number)
> 	return (guess_number)

That block of code is a huge step backwards from what you already
 had. So let's go back a step. 

def get_guess(guess_number):
    print "(",guess_number,")""Plese enter a guess:"
    current_guess = raw_input()
    return int(guess_number

First thing to do is decide what that function is 'supposed' to
 do. What do you suppose a caller might expect as a return value?
 Once you've decided a description,  write it down as a set of
 comments (or docstring,  but that's another lesson).

> 
>> 
>> Then, you use the parameter ‘guess_number’, create a new integer from
>> it, and return that integer. I think you've used the wrong name for the
>> ‘int()’ parameter.
> Well, since there are no loops allowed I’m guessing get_guess will be called 9 times.

It will be called (up to) 9 times even after you learn about
 loops.  It's called get_guess, not get_guesses. 

>  I believe guess_number is the number of tries the user has used.
> So;
> (1) Please enter a guess: 
> (2) Please enter a guess:

If that's a specification, then add it to your comments above.  I
 would guess you're missing a print in the function.
 



-- 
DaveA



More information about the Tutor mailing list