[Tutor] creating a dictionary for capital quiz program

Stephanie Quiles stephanie.quiles001 at albright.edu
Tue Jun 2 18:25:25 CEST 2015


What is  the +k+ called? How exactly does it work? I'm a big confused on that... 

Stephanie Quiles
Sent from my iPhone

> On Jun 2, 2015, at 12:17 PM, Peter Otten <__peter__ at web.de> wrote:
> 
> 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 at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list