代码:
#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