[Tutor] Step Value

Vincent Balmori vincentbalmori at yahoo.com
Fri Jun 17 04:26:07 CEST 2011


"def spam(n=3):
    """Return n slices of yummy spam."""
    return "spam "*n

And here it is in use:

>>> spam(4)
'spam spam spam spam '
>>> spam()  # just use the default
'spam spam spam '

Can you see what I did to set the default value for n? Read the function definition line "def spam... " carefully.

-- Steven"

This is my new code for a default step value based on your feedback Steve:

def ask_number(question, low, high, step):
    """Ask for a number within a range."""
    response = None
    if step == None:
        step = 1
    while response not in range(low, high, step):
        response = int(input(question))
    return response
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110616/91bf8300/attachment-0001.html>


More information about the Tutor mailing list