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 - [email protected]
http://mail.python.org/mailman/listinfo/tutor