《Python编程:从入门到实践》课后习题-第6章

6-1 人

#6-1 人

people = {'first_name':'Whitney','last_name':'Houston','age':56,'city':'New Jersey'}
print people

6-2 喜欢的数字

#6-2 喜欢的数字

dic = {'Rebecca':6,'Rihana':8,'Arriana':9,'Cristina':50,'Jessica':1}
print dic

6-3 词汇表

#6-3 词汇表

dic = {'lower':'全部小写','sort':'永久性排序','strip':'删除首尾空白','title':'首字母大写','pop':'删除'}
print ('lower : ' + dic['lower'])
print ('\nsort : ' + dic['sort'])
print ('\nstrip : ' + dic['strip'])
print ('\ntitle : ' + dic['title'])
print ('\npop : ' + dic['pop'])

6-4 词汇表2

#6-4 词汇表2

dic = {'lower':'全部小写','sort':'永久性排序','strip':'删除首尾空白','title':'首字母大写','pop':'删除',}
for key,value in dic.items():
    print(key + ' : ' + value)
print ("\n")
dic['min']='最小值'
dic['max']='最大值'
dic['sum']='总和'
dic['insert']='插入元素'
dic['sorted']='临时排序'
for key,value in dic.items():
    print( key + ' : ' + value)

6-5 河流

#6-5 河流

dic = {'The Mississippi River':'America','The Nile':'Egypt','The Yangtze River':'China'}
for river,country in dic.items():
    print(river + " runs through " + country + ".")
for river in dic.keys():
    print (river)
for country in dic.values():
    print (country)

6-6 调查

#6-6 调查

favorite_languages = {'jen':'python','sarah':'c','edward':'ruby','phil':'python',}
list = ['jen','rebecca','edward','cristina']
for name,language in favorite_languages.items():
    if name in list:
        print(name + ", Thank you very much!")
    else:
        print(name + ", Welcome to join us!")

6-7 人

#6-7 人

people1 = {'first_name':'Whitney','last_name':'Houston','age':56,'city':'New Jersey'}
people2 = {'first_name':'Jane','last_name':'Zhang','age':34,'city':'Chengdu'}
people3 = {'first_name':'Stefani Joanne Angelina','last_name':'Germanotta','age':32,'city':'Manhattan'}
people = [people1,people2,people3]
for information in people:
    print(information)

6-8 宠物

#6-8 宠物

milk = {'type':'cat','master\'s name':'Rebecca'}
jerry = {'type':'dog','master\'s name':'Cristina'}
dudu = {'type':'bird','master\'s name':'Jenny'}
momo = {'type':'tortoise','master\'s name':'Arriana'}
lists = [milk,jerry,dudu,momo]
for animal in lists:
    print (animal)

6-9 喜欢的地方

#6-9 喜欢的地方

favorite_places = {'Rebecca':['Japan','China','Egypt'],'Cristina':['France','America','China'],'Arriana':['England','China']}
for name,countries in favorite_places.items():
    print (name)
    for country in countries:
        print (country)

6-10 喜欢的数字

#6-10 喜欢的数字

dic = {'Rebecca':[6,55,264],'Rihana':[8,65,321],'Arriana':[9,88],'Cristina':[50,233],'Jessica':[1,99,666]}
for name,favorite_numbers in dic.items():
    print (name)
    for number in favorite_numbers:
        print(number)

6-11 城市

#6-11 城市

cities = {
    'Wuhan':{
        'country':'China',
        'population':'14 hundred millions',
        'fact':'A beautiful country.',
        },
    'New York':{
        'country':'America',
        'population':'3 hundred millions',
        'fact':'Has 50 states.'
        },
    'Tokyo':{
        'country':'Japan',
        'population':'1 hundred millions',
        'fact':'Has some attractions.',
        },
    }

for city,values in cities.items():
    print (city)
    for key,value in values.items():
        print (key)
        print (value)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值