# 6-1 friend1 = { 'first_name' : 'Donald', 'last_name' : 'Trump', 'age' : '71', 'city' : 'New York', } for key in friend1: print(key + ' is '+friend1[key]) # 6-5 rivers = { 'changjiang river' : 'china', 'mississippi river' : 'america', 'nile' : 'egypt' } for key in rivers.keys(): print('The ' + key.title() + ' runs through ' + rivers[key].title() + '.') # 6-7 friend2 = { 'first_name' : 'Barack', 'last_name' : 'Obama', 'age' : '56', 'city' : 'Hawaii', } friend3 = { 'first_name' : 'Cheng', 'last_name' : 'Long', 'age' : '63', 'city' : 'Hong Kong' } people = [friend1 , friend2 , friend3] for fri in people: for key in fri.keys(): print(key.title() + ':' + fri[key] ) print('') # 6-9 favorite_places = { 'Trump' : ['Shanghai' , 'Beijing'], 'Obama' : ['Guangzhou', 'Hangzhou'], 'Mike' : ['Xiamen','Beijing'] } for friend in favorite_places: print('My friend ' + friend + "'favorite places are ", end='') for place in favorite_places[friend]: print(place , end = ' ') print() # 6-10 cities ={ 'Guangzhou' : { 'country' : 'China', 'population(thousand)' : 14498, 'fact' : 'The city is in the south of China.' , }, 'London' : { 'country' : 'England', 'population(thousand)' : 8280, 'fact' : 'It is the capital of England.' , }, 'New York' : { 'country' : 'America', 'population(thousand)' : '8510', 'fact' : "It's an international city." , }, } for key_city in cities: print(key_city + ':') for inf in cities[key_city].keys(): print('\t' + inf + ':' + str(cities[key_city][inf]))
3.21python作业
猜你喜欢
转载自blog.csdn.net/control_xu/article/details/79674170
今日推荐
周排行