python第六章课后题答案_Python编程:从入门到实践的动手试一试答案(第六章)...

#6-1 人

ergou = {'first_name':'qili','last_name':'yang','city':'beijing'}

print(ergou['first_name'])

print(ergou['last_name'])

print(ergou['city'])1

2

3

4

5

#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))1

2

3

4

5

6

7

8

9

10

#6-3 词汇表

vocabulary = {'列表':'值可改','元组':'值不可改'}

for name,meaning in vocabulary.items():

print(name + ':' + meaning)1

2

3

4

#6-4 词汇表2

略1

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() + '.')1

2

3

4

5

#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())1

2

3

4

5

6

7

8

9

10

11

12

13

#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')1

2

3

4

5

6

7

8

9

10

#6-8 宠物

lili = {'type':'dog','owner':'ergou'}

qq = {'type':'cat','owner':'qiqi'}

pets =[lili,qq]

for pet in pets:

print(pet)1

2

3

4

5

6

#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)1

2

3

4

5

6

7

8

9

10

#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))1

2

3

4

5

6

7

8

9

10

11

12

#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)1

2

3

4

5

6

7

8

9

10

6-12 扩展

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值