Re: [Tutor] Newbie question re. Functions

2006-02-01 Thread Jon Moore
Thats fine, but what differance does it make?I can see no way that it improves the code.I assume later on when the function is called, it should look as follows:move = ask_number("Where will you move? (0-8): ", 0, NUM_SQUARES, 1)
JonOn 01/02/06, Ed Singleton <[EMAIL PROTECTED]> wrote:
On 31/01/06, Jon Moore <[EMAIL PROTECTED]> wrote:> Improve the function ask_number() so that the function can be called with a> step value. Make the default value of step 1.
>> The function looks like this:>> def ask_number(question, low, high):> """Ask for a number within the range"""> response = None> while response not in range(low, high):
> response =  int(raw_input(question))> return responseTo be honest, this made sense to me.  I assumed the author wants youto be able to do the following:ask_number("Give me an even number between 1 and 10", 1, 10, 2)
The solution would be:def ask_number(question, low, high, step=1):"""Ask for a number within the range"""response = Nonewhile response not in range(low, high, step):
response =  int(raw_input(question))return responseBut I definitely agree that he said it very, very badly.Ed___Tutor maillist  -  
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor-- Best Regards
Jon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-02-01 Thread Ed Singleton
On 31/01/06, Jon Moore <[EMAIL PROTECTED]> wrote:
> Improve the function ask_number() so that the function can be called with a
> step value. Make the default value of step 1.
>
> The function looks like this:
>
> def ask_number(question, low, high):
> """Ask for a number within the range"""
> response = None
> while response not in range(low, high):
> response =  int(raw_input(question))
> return response

To be honest, this made sense to me.  I assumed the author wants you
to be able to do the following:

ask_number("Give me an even number between 1 and 10", 1, 10, 2)

The solution would be:

def ask_number(question, low, high, step=1):
"""Ask for a number within the range"""
response = None
while response not in range(low, high, step):
response =  int(raw_input(question))
return response

But I definitely agree that he said it very, very badly.

Ed
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Alan Gauld
> Are you the author of Learn to Program Using Python: A Tutorial for
> Hobbyists, Self-starters and All Who Want to Learn the Art of Computer
> Programming?

Yes.

> Is the book still available as a web site?

Yes. It has been substantially rewritten sionce the book was done to 
cover more recent features of Python. But the basic structure and 
content is still the same. The book has 3 chapters whose copyright 
belongs to Addison Wesley and thus are not on the web site but 
OTOH the web site has several topics which were written after 
the book was published

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Jon Moore
AlanAre you the author of Learn to Program Using Python: A Tutorial for Hobbyists, Self-starters and All Who Want to Learn the Art of Computer Programming?
Is the book still available as a web site?JonOn 31/01/06, Alan Gauld <[EMAIL PROTECTED]
> wrote:> So a general recommendation to authors is to have a member of the target
> audience "test" the book. You Jon have done that but at some cost to you> and those of us on this list.One advantage of doing my book as a web site first was that I had plentyof testers before committing to print (over 100k visitors). Mind you the
paperversion still had plenty of mistakes but mostly those were typos...Alan G.-- Best RegardsJon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Jon Moore
DannyMany thanks for that, I notice a few erratas that I am yet to come up against. This will save my sanity (well some of it)1JonOn 31/01/06, 
Danny Yoo <[EMAIL PROTECTED]> wrote:
On Tue, 31 Jan 2006, Jon Moore wrote:> I have been looking for contact details for the author to ask him what> he was eluding to with the exercise, but to no avail.Hi Jon,I did find errata here:
http://www.muskalipman.com/ptr_detail.cfm?group=Programming&all=1&isbn=1-59200-073-8(bottom of the page)
but as far as contact information, I haven't been able to find anything.I do agree the challenege exercise as you've put it seems somewhatnonsensical.  *grin*
-- Best RegardsJon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Alan Gauld
> So a general recommendation to authors is to have a member of the target 
> audience "test" the book. You Jon have done that but at some cost to you 
> and those of us on this list.

One advantage of doing my book as a web site first was that I had plenty
of testers before committing to print (over 100k visitors). Mind you the 
paper
version still had plenty of mistakes but mostly those were typos...


Alan G. 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Danny Yoo


On Tue, 31 Jan 2006, Jon Moore wrote:

> I have been looking for contact details for the author to ask him what
> he was eluding to with the exercise, but to no avail.

Hi Jon,

I did find errata here:

http://www.muskalipman.com/ptr_detail.cfm?group=Programming&all=1&isbn=1-59200-073-8

(bottom of the page)

but as far as contact information, I haven't been able to find anything.
I do agree the challenege exercise as you've put it seems somewhat
nonsensical.  *grin*

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Jon Moore
I know. Its hard enough for someone like me as it is without things like this complicating it!I have another one for the group, but I will save it for another day ;)I have been looking for contact details for the author to ask him what he was eluding to with the exercise, but to no avail.
JonOn 31/01/06, Bob Gailer <[EMAIL PROTECTED]> wrote:
Jon Moore wrote:> Hi,>> I am still working my way through my 'Python for absolute beginners> book' and have hit a brick wall with one of the end of chapter exercises.>> The challenge says:
>> Improve the function ask_number() so that the function can be called> with a step value. Make the default value of step 1.>> The function looks like this:>> def ask_number(question, low, high):
> """Ask for a number within the range"""> response = None> while response not in range(low, high):> response =  int(raw_input(question))> return response
>> The author has not eluded to 'step values' in anyway that I can see in> the proceeding chapters!This lights my frustration fire. I wonder whether the author tested thebook?When I worked for a training company I was asked to test a new on-line
course on JCL. I demurred by saying "But I don't know JCL.". The replywas "that's exactly what we want!"So a general recommendation to authors is to have a member of the targetaudience "test" the book. You Jon have done that but at some cost to you
and those of us on this list.-- Best RegardsJon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Bob Gailer
Jon Moore wrote:
> Hi,
>
> I am still working my way through my 'Python for absolute beginners 
> book' and have hit a brick wall with one of the end of chapter exercises.
>
> The challenge says:
>
> Improve the function ask_number() so that the function can be called 
> with a step value. Make the default value of step 1.
>
> The function looks like this:
>
> def ask_number(question, low, high):
> """Ask for a number within the range"""
> response = None
> while response not in range(low, high):
> response =  int(raw_input(question))
> return response
>
> The author has not eluded to 'step values' in anyway that I can see in 
> the proceeding chapters!
This lights my frustration fire. I wonder whether the author tested the 
book?

When I worked for a training company I was asked to test a new on-line 
course on JCL. I demurred by saying "But I don't know JCL.". The reply 
was "that's exactly what we want!"

So a general recommendation to authors is to have a member of the target 
audience "test" the book. You Jon have done that but at some cost to you 
and those of us on this list.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Jon Moore
I guess I am not going mad then!I will skip this exercise and move on.ThanksJonOn 31/01/06, Alan Gauld <
[EMAIL PROTECTED]> wrote:Hi Jon,> Improve the function ask_number() so that the function can be called with
> a> step value. Make the default value of step 1.If its any consolation that doesn't really mean much to me either.I understand the concept of step value - range() takes one forexample, check the docs.
But how a step value would be used in this kind of user-input scenarioI have no idea!def ask_number(question, low, high):"""Ask for a number within the range"""
response = Nonewhile response not in range(low, high):response =  int(raw_input(question))return responseThe only possibility I can think of is that the step value is used tonarrow the acceptable range each time round the loop. But given
we don't necessarily tell the user what the range is that would beweird. We'd need to modify question as we go or something.On the assumption you aren't being marked on this I'd justmake up your own mind what it should do and do it! :-)
...and treat it as a good example of a bad statement ofrequirements!Alan G-- Best RegardsJon Moore
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Alan Gauld
Hi Jon,

> Improve the function ask_number() so that the function can be called with 
> a
> step value. Make the default value of step 1.

If its any consolation that doesn't really mean much to me either.
I understand the concept of step value - range() takes one for
example, check the docs.

But how a step value would be used in this kind of user-input scenario
I have no idea!

def ask_number(question, low, high):
"""Ask for a number within the range"""
response = None
while response not in range(low, high):
response =  int(raw_input(question))
return response

The only possibility I can think of is that the step value is used to
narrow the acceptable range each time round the loop. But given
we don't necessarily tell the user what the range is that would be
weird. We'd need to modify question as we go or something.

On the assumption you aren't being marked on this I'd just
make up your own mind what it should do and do it! :-)

...and treat it as a good example of a bad statement of
requirements!

Alan G 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Newbie question re. Functions

2006-01-31 Thread Kent Johnson
Jon Moore wrote:
> Hi,
> 
> I am still working my way through my 'Python for absolute beginners 
> book' and have hit a brick wall with one of the end of chapter exercises.
> 
> The challenge says:
> 
> Improve the function ask_number() so that the function can be called 
> with a step value. Make the default value of step 1.
> 
> The function looks like this:
> 
> def ask_number(question, low, high):
> """Ask for a number within the range"""
> response = None
> while response not in range(low, high):
> response =  int(raw_input(question))
> return response
> 
> The author has not eluded to 'step values' in anyway that I can see in 
> the proceeding chapters!

I have the book and I don't understand what he is asking for in that 
question either.

To me a 'step value' would be something that alters a sequence, for 
example the third argument to range() is a step value:
  >>> help(range)
Help on built-in function range in module __builtin__:

range(...)
 range([start,] stop[, step]) -> list of integers

 Return a list containing an arithmetic progression of integers.
 range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
 When step is given, it specifies the increment (or decrement).
 For example, range(4) returns [0, 1, 2, 3].  The end point is omitted!
 These are exactly the valid indices for a list of 4 elements.
  >>> range(0, 6)
[0, 1, 2, 3, 4, 5]
  >>> range(0, 6, 2)
[0, 2, 4]

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor