[Tutor] Step Value

ALAN GAULD alan.gauld at btinternet.com
Sat Jun 18 02:32:20 CEST 2011



>> def ask_number(question, low, high, step = 1):
>>   """Ask for a number within a range."""
>>   response = None
>>   while response not in range(low, high, step):
>>       response = int(input(question))
>>   return response
>
> With the only comment being that you don't really need the
> response=None line because response always gets set
> inside the loop.

> But the value of response is used in starting the loop (it is needed
> to test whether the loop should be gone through a first time), so one
> _does_ need that line.

Doh! Stoopid me, of course it is.
So the function is pretty much fine as it is.

Apologies,

Alan G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110618/4a07cf21/attachment.html>


More information about the Tutor mailing list