[Tutor] Problem with Exception Error

Alan Gauld alan.gauld at blueyonder.co.uk
Sun Aug 22 22:41:59 CEST 2004

> I know I am doing this wrong but I can't figure out how to 
> get it to raise the error so that it will print out 
> "You must type y or n!" 

There is no error. At least, not so far as Python is concerned, 
so the except never gets executed. Try a simple else statement:

def YesNo():
    while True:
        yn = raw_input("\r\nWhould you like to play again? ")
        if yn == 'y':  # might try:  if yn in 'yY' instead
        elif yn == 'n':   # and elif yn in 'nN'
           print "Thank you for playing!"
            print "You must type y or n!"


Alan G

More information about the Tutor mailing list