所以我定义了这个函数,它询问你一个国家的名字,然后给你一个有趣的事实。它应该询问您是否要将您询问的国家添加到字典中(如果它还不知道)。我认为代码很好。但是在询问您之后,它并没有真正将新的国家事实添加到字典中:/ 有人可以找出问题吗?
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.")