, поэтому я пытаюсь вызвать словарь в словаре и использовать ключи в качестве значений, но я все попытки достичь его не удалось. Вот где я, обратите внимание, что все операторы печати после выражения if терпят неудачу.Словарь вызывает в словаре
def main():
print("This program tells you about the animal of your choice")
animal=input("What animal would you like to look up: ")
animal=animal.lower()
d2={
"lion":{"name":"Lion","species":"Panthera leo",
"image":"http://en.wikipedia.org/wiki/File:Lion_waiting_in_Namibia.jpg",
"fact":"Vulnerable species"},
"dog":{"name:":"Dog","species":"Canis lupus familiaris",
"image":"http://en.wikipedia.org/wiki/File:YellowLabradorLooking_new.jpg",
"fact":"Common house pet"},
"hippo":{"name":"Hippo","species":"Hippopotamus amphibius",
"image":"https://en.wikipedia.org/wiki/Hippopotamus#/media/File:Hippopotamus_-_04.jpg",
"fact":"Erbivorous mammal"},
"cat":{"name":"Cat","species":"Felis catus",
"image":"https://en.wikipedia.org/wiki/Cat#/media/File:Cat_poster_1.jpg",
"fact":"Purring hunters"}
}
if animal in d2:
print(d2(animal["name"]), "is the common name")
print(d2(animal["species"]), "is its latin name")
print(d2(animal["image"]), "is a picture of", animal)
print(d2(animal["fact"]),)
else:
print("Not in dicionary, try lion, dog, hippo, or cat")
main()
Некоторые отступы исчезли, когда я вставил код, так что почему текст выглядит так смешано в d2 – Magnus
Элементы 'dict' имеют доступ к' [] ', а не'() '. – sobolevn
Вы заметили, что используете скобки вместо скобок для доступа к словарю? – TigerhawkT3