[Tutor] Step Value

Alan Gauld alan.gauld at btinternet.com
Fri Jun 17 23:03:31 CEST 2011


"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.

If you don't understand how your code answered
the question, feel free to reply with specific issues,
like a particular statement you don't get or whatever.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list