[Tutor] Newbie question re. Functions
alan.gauld at freenet.co.uk
Tue Jan 31 12:24:12 CET 2006
> Improve the function ask_number() so that the function can be called with
> 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))
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
More information about the Tutor