python入门到实践第六章答案_python编程 从入门到实践 第六章 课后习题(6-1~6-12)...

# 动手试一试

#6—1

lingling={

'first_name':'lingling',

'last_name':'huang',

'age':'13',

'city':'dezhou',

}

print(lingling)

#6—2 喜欢的数字

friends={

'lingling':'5',

'daming': '3',

'sam': '2',

'tom': '1',

}

print(friends)

#6_3 词汇表

words={

'dog':'wangwang',

'cat':'miaomiao',

'bird':'jiji',

'dragon':'wawa',

}

for word in words:

print(word+" : "+words[word])

for word in words:

print(word+"\n\t"+words[word])

# 动手试一试

# 6-4 词汇表 2:

favorite_languages={

'jen':'python',

'sarah':'c',

'daming':'java',

'sam':'c++',

}

for name,language in favorite_languages.items():

print(name+' : '+language+' .')

# 6-5 河流

rivers={

'huanghe':'china',

'nile':'egyp',

'orange':'apple',

}

for river,country in rivers.items():

print(" the "+river+"runs through "+country+' .')

for river in rivers.keys():

print(river)

for country in rivers.values():

print(country)

# 6-6 调查:

favorite_languages={

'jen':'python',

'sarah':'c',

'daming':'java',

'sam':'c++',

}

people={'tom','sam','daming','lingling'}

for man in people:

if man in favorite_languages.keys():

print("thanks "+man)

else:

print("would you like to join us? "+man)

## 动手试一试

# 6-7 人:

lingling={

'first_name':'lingling',

'last_name':'huang',

'age':'13',

'city':'dezhou',

}

daming={

'first_name': 'daming',

'last_name': 'li',

'age': '12',

'city': 'beihai',

}

sam={

'first_name': 'sam',

'last_name': 'wang',

'age': '13',

'city': 'tianjin',

}

people=[sam,daming,lingling]

for p in people:

print(p)

# 6-8 宠物

peter={'kind':'dog','zhuren':'lingling'}

qiaoen={'kind':'pig','zhuren':'daming'}

tuomasi={'kind':'cat','zhuren':'tom'}

pets=[peter,qiaoen,tuomasi]

for p in pets:

print(p)

# 6-9 喜欢的地方

favorite_places={

'daming':['beijing','beihai'],

'lingling':['shanghai','chengdu','chongqing'],

'tom':['dezhou','tianjin'],

}

for place in favorite_places.items():

print(place)

# 6-10 喜欢的数字

friends={

'lingling':['5','3'],

'daming': ['3','4','2'],

'sam': ['2','4','5','6'],

'tom': ['1'],

}

for friend in friends.items():

print(friend)

#6-11 城市

cities={

'dezhou':{

'country':'china',

'population':'13 billion',

'fact':'great',

},

'newyork':{

'country':'america',

'population':'3 billion',

'fact':'wide',

},

'dongjing':{

'country':'japan',

'population':'1 billion',

'fact':'little',

},

}

for city_name,city_info in cities.items():

print('\n\tcity name: '+city_name)

print("\tcountry: "+city_info['country'])

print("\tpopulation: "+city_info['population'])

print("\tfact: " + city_info['fact'])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值