[Tutor] recursive?

Alexandre Ratti alex at gabuzomeu.net
Sat Sep 13 15:08:21 EDT 2003


Hello Andrea,


Andrea Spitaleri wrote:
>        q=raw_input("Do you want try again?")
>        if q == 'y':         #without ' ' you get error
>                      else:
>                print 'bye'
> else:

> that small silly program works but I would like to insert another 
> condition. after typing y after 'do you want try again?' how I can start 
> again all the program, asking again the three values?

You can wrap your program in this kind of structure:

 >>> while 1:
... 	q = raw_input("Do you want try again? (y/n)")
... 	if q == 'n':
... 		break
... 	# run your program here

Basically, the program runs in an endless loop, since the "while 1" 
condition is always true. It will run until the user chooses "n" to 
break out of the loop.


Cheers.

Alexandre





More information about the Tutor mailing list