教材第六章课后习题 (部分)

代码:

#6.1
print(6.1)
friend_information = {
		'first_name' : 'Jack', 'last_name' : 'Ma', 
		'age' : 18, 'living city' : 'Hong Kong'}
for key,value in friend_information.items():
	print(key,":",value)
print()

#6.5
print(6.5)
dic5 = {'Tom' : 'boy', 'Jack' : 'boy', 'Mary' : 'girl'}
for name,sex in dic5.items():
	print(name+" is a "+sex+".")
for name in dic5.keys():
	print(name)
for sex in dic5.values():
	print(sex)
print()

#6.8
print(6.8)
Tom = {'host':'Tang Mu','age':'3'}
Jack = {'host':'Jie Ke','age':'4'}
Peter = {'host':'Bi De','age':'5'}
pets = [Tom,Jack,Peter]
for pet in pets:
	for key,value in pet.items():
		print(key + " : " + value,end=" ")
	print()
print()

#6.11
print(6.11)
cities = {
	'Guangzhou':{'country':'China','Population':'quantities'},
	'Beijing':{'country':'China','Population':'lots of'},
	'Nanning':{'country':'China','Population':'many'}
}
for city,info in cities.items():
	print(city+':')
	for key,value in info.items():
		print(key+':'+value,end=' ')
	print()
print()

输出:

6.1
first_name : Jack
last_name : Ma
age : 18
living city : Hong Kong

6.5
Tom is a boy.
Jack is a boy.
Mary is a girl.
Tom
Jack
Mary
boy
boy
girl

6.8
host : Tang Mu age : 3 
host : Jie Ke age : 4 
host : Bi De age : 5 

6.11
Guangzhou:
country:China Population:quantities 
Beijing:
country:China Population:lots of 
Nanning:
country:China Population:many 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值