Alan Gauld wrote: > On 02/06/15 15:15, Peter Otten wrote: > >> Not an optimization, but if the user enters neither Y nor N you might ask >> again instead of assuming Y. > > He does. He only breaks if the user enters N > >>> choice = input('Do you want to play again y/n: ') >>> if choice.upper() == 'N': >>> print('end of game') >>> break >>> elif choice.upper() != 'Y': >>> print("invalid choice") > > Y goes round again silently. > Anything other than Y or N prints the error then tries again.
... with the next state. I meant that instead the question "Do you want to play again y/n:" should be repeated until there is a valid answer, either y or n. Current behaviour: $ python capitals.py Enter the capital of Mississippi :Jackson Correct Do you want to play again y/n: x invalid choice Enter the capital of Oklahoma : ... So "x" is a synonum for "n". Suggested behaviour: $ python capitals.py Enter the capital of Mississippi :Jackson Correct Do you want to play again y/n: x invalid choice Do you want to play again y/n: z invalid choice Do you want to play again y/n: n end of game ... _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor