Я пытаюсь извлечь все элементы из определенного ключа в словаре.Код работает, но я продолжаю получать оператор None
в выводе из моей функции general_info
.Другая функция specific_info
работает нормально.Любое предложение?Большое спасибо.
countries = {
"canada": {
'name': "Canada",
'location': "North America",
'currency': "Canadian Dollar",
'capital city': "Ottawa",
'population': "32.268.240",
'area': "9.970.610 km2"
},
"brazil": {
'name': "Brazil",
'location': "South America",
'currency': "Brazilian Real",
'capital city': "Brasilia",
'population': "186.404.900",
'area': "8.514.877 km2"
},
"ukraine": {
'name': "Ukraine",
'location': "Europe",
'currency': "Ukrainian Hryvnia",
'capital city': "Kyiv",
'population': "46.480.700",
'area': "603.700 km2"
},
"haiti": {
'name': "Haiti",
'location': "North America",
'currency': "Haitian Gourde",
'capital city': "Port-au-Prince",
'population': "8.527.777",
'area': "27.750 km2"
},
"albania": {
'name': "Albania",
'location': "Europe",
'currency': "Albanian Lek",
'capital city': "Tirana",
'population': "3.129.678",
'area': "28.748 km2"
},
"india": {
'name': "India",
'location': "Asia",
'currency': "Indian Rupee",
'capital city': "New Delhi",
'population': "1.103.371.000",
'area': "3.287.263 km2"
}
}
def general_info(c_name):
for key, val in countries[c_name].items():
info = print(c_name.title() + " " + key + " is " + val)
return info
def specific_info(c_name, info):
if c_name in countries and info in countries[c_name].keys():
return (info.title() + " from " + c_name.title() + " is " + countries[c_name][info])
ask_country = input("Country name: ")
ask_info = input("Information requested: ")
c_name = ask_country.lower()
info = ask_info.lower()
print(general_info(c_name))
print()
print(specific_info(c_name, info))