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 <[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 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
--
Best Regards
Jon Moore
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor