[Tutor] Step Value

James Reynolds eire1130 at gmail.com
Wed Jun 15 21:57:35 CEST 2011


Without looking at your code,

What is it that you know that's wrong about it? Are you getting a return
value which you know is incorrect, is the program throwing error and you
aren't sure why? or do you just suspect it is wrong but you aren't sure?

When posing a question, it's helpful to know the things above because those
answering might not know exactly what your problem is.

with regards to the step value of range, here,  "if response in range(low,
high, 1)" the default step value of range() is 1, so you don't need to have
that. range(1,3) will give you a list [1,2], for example.


On Wed, Jun 15, 2011 at 3:35 PM, Vincent Balmori
<vincentbalmori at yahoo.com>wrote:

> I am still working on that one question in the absolute beginners with the
> the ask_number function and step value. Honestly, I still have no idea what
> to do. This is one of my many attempts, but I know that it's wrong.
>
> 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
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110615/e0bc228e/attachment-0001.html>


More information about the Tutor mailing list