vendredi 25 août 2017

Random key from dictionary does not recognize it's value when entered as an input

Trying to do this through dictionary but it is not working. Is there a solution to this? The assignment is user asked to guess the capital of a randomly chosen country from dictionary. When user writes the answer, it will be turned into value and checked if matches with country key.

import random
capitals = {'England': 'London', 'Spain': 'Madrid', 'France': 'Paris'}
rand= (random.choice (list(capitals)))
for i in capitals:
        inp= input("what's is the capital of "+rand+ ":   ")
        if inp.upper()==capitals[i].upper():
            print ("correct")
            break
        else:
            print ("think again")




Aucun commentaire:

Enregistrer un commentaire