[Tutor] Step Value
Andre Engels
andreengels at gmail.com
Sat Jun 18 00:54:16 CEST 2011
On Fri, Jun 17, 2011 at 11:03 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> "Vincent Balmori" <vincentbalmori at yahoo.com> wrote
>
>> Here is my updated code. As simple as this may be, I am a little lost
>> again.
>
> I'm not sure why you are lost because that's pretty much it.
>
>> ... at this point (especially after one week) this is when me being
>> given the answer with an explanation will help me much more, so I can
>> understand how it works better.
>
> The answer is:
>
>> 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.
--
André Engels, andreengels at gmail.com
More information about the Tutor
mailing list