[Tutor] creating a dictionary for capital quiz program

Alan Gauld alan.gauld at btinternet.com
Tue Jun 2 17:45:54 CEST 2015


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.


-- 
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




More information about the Tutor mailing list