Tuesday, 17 September 2013

Why isn't my function appending a key-value to the dictionary?

Why isn't my function appending a key-value to the dictionary?

So I defined this function that queries you about the name of a country
and then gives you a fun fact about it. It's supposed to ask you if you
want to add the country you asked about to the dictionary (if it doesn't
already know it). I think the code is just fine. But it doesn't really add
the new country-fact to the dictionary after it asks you :/ Can someone
please identify the problem?
def countries():
param = input("please enter the country you'd like a fun fact about")
listofcountries = {"Kuwait": "has 10% of the world's oil reserves.",
"UAE": "has the world's highest free-standing structrure, Burj
Khalifa.", "Qatar": "is hosting the FIFA 2022 world cup.", "Saudi
Arabia": "is the largest GCC country.", "Bahrain": "held the Dilmun
civilization, one of the world's oldest civilizations.", "Oman": "is
known for its beautiful green mountains."}
if (param in listofcountries):
print ("I know something about", param)
print (param, listofcountries[param])
else:
print ("I don't know anything about", param)
add_yesorno = input("Would you like to add something to the list?
(yes or no)")
if add_yesorno == 'yes':
country_name = input("What's its name again?")
add_yes = input("please finish this sentence. This country...")
print ("Thanks a lot for contributing to the list!")
listofcountries[country_name] = add_yes
else:
print ("Thanks then! See you later.")

No comments:

Post a Comment