thank you again but i think i found a way to fix it

On 8/17/06, Danny Yoo <[EMAIL PROTECTED] > wrote:


>> > Mr. Yoo im working on a program to write a sudoku puzzle and if
>> > something is wrong with the last row i need to re make the whole puzzle
>> > over again.

>> Here's a separate question that's related to the first: can you write a
>> function that asks the user to enter a word, and continues prompting until
>> the user enters a non-empty word?

Hi Amadeo,


> Yes I can Mr. Yoo, but i dont really want to make my whole program a
> loop.

Ok.  Why not?  I'm curious: is there a particular constraint you're trying
to work under, or is it something else?

Also, I'm not sure what you mean by "whole program".


In any case, here's a way to do it without an explicit 'for' or 'while'
loop:

####################################
def ask_for_input():
     msg = raw_input("enter a word:")
     if msg:
         return msg
     else:
         return ask_for_input()
####################################

This would not be the idiomatic way to do this in Python only because of a
technical limitation in the main Python implementation (it doesn't support
"tail call optimization").

Still, would this be more acceptable to you, or do you also consider this
a "loop"?

(Personally, I do. *grin*)

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to