您的位置:首页 > 编程语言 > Python开发

《Python编程——从入门到实践》第六章部分习题解

2018-03-21 22:06 591 查看
# 6-3
words = {'int' : 'integer', 'char' : 'character', 'long' : 'long integer', 'float' : 'single-precision floating-point', 'double' : 'double-precision floating-point'}
for noun, means in words.items():
print(noun + ' : ' + means)

# 6-5
rivers = {'Danube' : 'Germany', 'Danube' : 'Austria', 'Nile' : 'Egypt', 'Yellow River' : 'China'}
for river,country in rivers.items():
print('The ' + river + ' runs through ' + country)
for key in set(rivers.keys()):
print(key)
for value in set(rivers.values()):
print(value)

# 6-11
cities = {'New York' : {'country' : 'America', 'population' : '8.51m', 'fact' : 'There is a Wall Street.'}, 'London' : {'country' : 'England', 'population' : '8.28m', 'fact' : 'There is a Big Ben.'}, 'Hong Kong' : {'country' : 'China', 'population' : '7.41m', 'fact' : 'There is a Disneyland.'}}
for city,city_info in cities.items():
print('City:' + city)
print('\tCountry:' + city_info['country'])
print('\tPopulation:' + city_info['population'])
print('\tFact:' + city_info['fact'])
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: