[Tutor] Newbie question re. Functions
Jon Moore
jonathan.r.moore at gmail.com
Wed Feb 1 15:38:01 CET 2006
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)
Jon
On 01/02/06, Ed Singleton <singletoned at gmail.com> wrote:
>
> On 31/01/06, Jon Moore <jonathan.r.moore at gmail.com> 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 at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
Best Regards
Jon Moore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060201/bc024d76/attachment-0001.html
More information about the Tutor
mailing list