On 02/06/15 17:17, Peter Otten wrote:

          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.

OK, I agree that it's a rad unconventional.
I thought you thought he was just quitting with the error message.

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

Yes this would be the normal idiom.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to