我有这个密码
def readCountries(self):
countryList = []
with open('countries.txt', 'r') as countryText:
for line in open('countries.txt', 'r'):
countries = countryText.read()
countryList.append(line.strip().split())
return countryList
他的代码输出如下:
[["Afghanistan",647500.0,25500100],["Albania",28748.0,2821977],...,["Zimbabwe",390580.0,12973808]]
t经过[name, area, population]
。我要做的是编写一个函数,从上面的代码中调用答案来获取国家列表,并进行二进制搜索,如果找到了国家信息,则打印它。示例:
printCountry("Canada")
Canada, Area: 9976140.0, Population: 35295770
printCountry("Winterfell")
I'm sorry, could not find Winterfell in the country list.
我不知道如何做这一部分,任何帮助是感激的。你知道吗
希望这有助于:
相关问题 更多 >
编程相关推荐