Python编程:从入门到实践的动手试一试答案(第六章)

#6-1 人
ergou = {'first_name':'qili','last_name':'yang','city':'beijing'}
print(ergou['first_name'])
print(ergou['last_name'])
print(ergou['city'])
#6-2 喜欢的数字
favorite_numbers = {
    'ergou':8,
    'qiqi':6,
    'pengpeng':7,
    'tiezhu':4,
    'dongzi':2,
    }
for name,number in favorite_numbers.items():
    print(name.title() + "'s favorite number is " + str(number))
#6-3 词汇表
vocabulary = {'列表':'值可改','元组':'值不可改'}
for name,meaning in vocabulary.items():
    print(name + ':' + meaning)
#6-4 词汇表2
#6-5 河流
rivers = {'nile': 'egypt','Yellow River':'china','Yangtze River':'china'}
for river,country in rivers.items():
    print('The ' + river.title() + ' runs through ' + country.title() + '.')
#6-6 调查
favorite_languages = {
      'jen': 'python',
      'sarah': 'c',
      'edward': 'ruby',
      'phil': 'python',
      }
users = ['jen','ergou','qiqi','sarah','edward','phil']

print("The following languages have been mentioned:")
for name in users:
    if name in favorite_languages.keys():
        print('谢谢' + name.title())
#6-7 人
ergou = {'first_name':'qili','last_name':'yang','city':'beijing'}
danliang = {'first_name':'danliang','last_name':'yang','city':'qingdao'}
mingliang = {'first_name':'mingliang','last_name':'zhu','city':'hefei'}
peoples = [ergou,danliang,mingliang]
for people in peoples:
    for k,v in people.items():
        print(k + ' is ' + v)
    print('\n')
#6-8 宠物
lili = {'type':'dog','owner':'ergou'}
qq   = {'type':'cat','owner':'qiqi'}
pets =[lili,qq]
for pet in pets:
    print(pet)
#6-9 喜欢的地方
favorite_places = {
    'ergou':['beijing','xi an'],
    'danliang':['shanghai'],
    'shitou':['dali','lasa','chongqing'],
    }
for k,v in favorite_places.items():
    print('\n'+ k + "'s favorite places :")
    for city in v:
        print(city)
#6-10 喜欢的数字
favorite_numbers = {
    'ergou':[8,1,3],
    'qiqi':[6],
    'pengpeng':[7,6,9,0],
    'tiezhu':[4,5],
    'dongzi':[2],
    }
for k,v in favorite_numbers.items():
    print('\n'+ k + "'s favorite numbers :")
    for number in v:
        print(str(number))
#6-11 城市
cities = {'beijing':{'country':'china','population':'*million','fact':'The political economic and cultural center'},
          'New York':{'country':'USA','population':'*million','fact':'International metropolis'},
          'Singapore':{'country':'singapore','population':'*million','fact':'city-state'}
         }
for k,v in cities.items():
    print('\n' + k.title())
    for ks,vs in v.items():
        print(ks + ' : ' + vs)
6-12 扩展
略
    原文作者:叫我小红
    原文地址: https://blog.csdn.net/weixin_39449570/article/details/78380624
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞