vendredi 23 mars 2018

if statement doesn't work properly in python

d={1:'a', 2:'b', 3:'c', 4:'a', 5:'d', 6:'e', 7:'a', 8:'b'}
value = raw_input("Choose a value to be searched: ")
data = ""
    if value in d:
         data = d.keys["value"]
         print(data)
    else:
          print "There isn't such value in the dictionary"

So I write 'a' and I want to get the key '1' but it skips "data = d.keys["value"] print(data)" and it prints me the message of "else"

What have I done wrong?

Aucun commentaire:

Enregistrer un commentaire