そこで、国名についてクエリを実行し、それに関する面白い事実を提供するこの関数を定義しました。質問した国を辞書に追加するかどうかを尋ねるはずです (まだわかっていない場合)。コード自体は問題ないと思います。しかし、それはあなたに尋ねた後、辞書に新しい国の事実を実際に追加しません:/誰かが問題を特定できますか?
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.")