Versuchen, erstellen Sie eine lookup-Funktion in python

Ich habe ein Wörterbuch mit einer Liste gefüllt mit Tupeln. Jedes Tupel sollte ein paar, z.B. (word, description_of_said_word).
Bisher habe ich dieses:

banana = ("banana", "a yellow fruit")
orange = ("orange", "a orange fruit")
apple = ("apple", "a green fruit") 
my_list = [banana, orange, apple]

def lookup():
    word = raw_input("Word to lookup: ")
    print ("\n")
    n = my_list.index(word)
    x = my_list[n][0]
    y = my_list[n][1]
    if word == x:
       print x, ":", y, "\n"
    else:
       print("That word does not exist in the dictionary")
lookup()

Wenn ich Schreibe, in der Bananen bekomme ich einen Fehler sagend, "ValueError: 'Banane' ist nicht in der Liste". Was mache ich falsch?

InformationsquelleAutor Erik.E | 2015-10-18
Schreibe einen Kommentar