I am copying and pasting your code here from the previous email:

def ask_number(question, low, high):
>     """Ask for a number within a range."""
>     response = None
>     if response in range(low, high, 1):
>       return response
>     while response not in range(low, high):
>         response = int(input(question))
>     return response
> I tried to find clues by looking at the later section that calls on the
> ask_number function:
> def human_move(board, human):
>     """Get human move."""
>     legal = legal_moves(board)
>     move = None
>     while move not in legal:
>         move = ask_number("Where will you move? (0 - 8):", 0, NUM_SQUARES)
>         if move not in legal:
>             print("\nThat square is already occupied, foolish human.
>  Choose another.\n")
>     print("Fine...")
>     return move



As to the question, I think what you are missing is, how do you make a
default value in a function parameter?

So, for example, let's say I have a function called, enchilada with a few
parameters. guac, spicey,

so it might look like this:

def enchildada(guac, spicey):
  do stuff with guac and spiceyness.
  return tasty_ness

And I can call that function like this:

a = enchilada(True, True)

But, let's say I want there to be a default vale for Spicey. Maybe I have
heartburn and I happen to enjoy heartburn every day at around noontime, so
my default option for spcicey is True.

I would then write the function like this:

def enchildada(guac, spicey=True):
  do stuff with guac and spiceyness.
  return tasty_nes

Now, when I call my enchilada function, I can call it like this:

a = enchilada(True) and the default value for spicey is True and it returns
a tasty encilada.

But, lets say my heartburn is beyond all rationality and I want a non-spicey
enchilada, i can override that default:

a = enchilada(True, False)

That is what the author meant by a default value and this just becomes a
variable you enter into the range function (so, a default of 1, and you can
change this to 2,3,etc)




On Wed, Jun 15, 2011 at 4:02 PM, Vincent Balmori
<vincentbalm...@yahoo.com>wrote:

> The question to that code I am trying to solve is
>
> "Improve the function *ask_number()* so that the function can be called
> with a step value. Make the default value of step *1*."
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to