Thats fine, but what differance does it make?<br><br>I can see no way that it improves the code.<br><br>I assume later on when the function is called, it should look as follows:<br><br>move = ask_number("Where will you move? (0-8): ", 0, NUM_SQUARES, 1)
<br><br>Jon<br><br><div><span class="gmail_quote">On 01/02/06, <b class="gmail_sendername">Ed Singleton</b> <<a href="mailto:singletoned@gmail.com">singletoned@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 31/01/06, Jon Moore <<a href="mailto:jonathan.r.moore@gmail.com">jonathan.r.moore@gmail.com</a>> wrote:<br>> Improve the function ask_number() so that the function can be called with a<br>> step value. Make the default value of step 1.
<br>><br>> The function looks like this:<br>><br>> def ask_number(question, low, high):<br>> """Ask for a number within the range"""<br>> response = None<br>> while response not in range(low, high):
<br>> response = int(raw_input(question))<br>> return response<br><br>To be honest, this made sense to me. I assumed the author wants you<br>to be able to do the following:<br><br>ask_number("Give me an even number between 1 and 10", 1, 10, 2)
<br><br>The solution would be:<br><br>def ask_number(question, low, high, step=1):<br> """Ask for a number within the range"""<br> response = None<br> while response not in range(low, high, step):
<br> response = int(raw_input(question))<br> return response<br><br>But I definitely agree that he said it very, very badly.<br><br>Ed<br>_______________________________________________<br>Tutor maillist -
<a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br><br clear="all"><br>-- <br>Best Regards
<br><br>Jon Moore