您的位置:首页 > 编程语言

2018.3.32 高级编程作业

2018-03-22 00:47 369 查看
6-1    使用字典存储一个熟人的信息
person={'first_name':'Yunzhi','last_name':'Wei','age':19,'city':'GZ'}
print(person)

6-4    使用字典存储词汇,遍历
slang={'buy some orange':'I am your father',
'Chen Duxiu':'Sit down',
'yingyingying':'make some girly noise',
'mo':'one kind of non-mainstream culture',
'senior':'show respect to SOMEONE'}
for k,v in slang.items():
print(k.title()+'\t:\t'+v)
slang['233']='LOL'
slang['zqsg']='showing feeling sincerely'
print('\n')
for k,v in slang.items():
print(k.title()+'\t:\t'+v)



6-6    创建调查人名单,已调查的表示感谢,未调查的发出邀请
survey={'A':99,'B':89,'D':79,'F':69}
person=['A','B','C','D','E','F','G']
for p in person:
if p in survey.keys():
print(p+', thank you for taking part in my survey')
else:

print(p+', I sincerely invite you to take my survey')



6-8    宠物 创建多个字典表示宠物,将宠物s放入一个列表中,遍历该列表
daoge={'name':'daoge','species':'dog','owner':'wzy'}
catie={'name':'catie','species':'cat','owner':'wyz'}
bear={'name':'bearbear','species':'bear','owner':'ybh'}
pets=[daoge,catie,bear]
for p in pets:
print('Name:\t\t'+p['name'].title()+'\nSpecies:\t'+p['species']+

'\nOwner:\t\t'+p['owner'].upper()+'\n')



6-10    喜欢的数字 每个人可以有好多喜欢的数字
likedNumbers={'WYZ':[1,2,3,4,5],'YBH':[5,9,8,6],'ZYX':[11,12,13]}
for name,num in likedNumbers.items():

print(name+':'+str(num))

6-11    创建名为cities的字典将三个城市名作为键;对于每座城市都创建一个字典
cities={'GZ':{'country':'China','population':'10000000','a fact':'GZer love delicious food'},
'BJ':{'country':'China','population':'6000000','a fact':"BJer add 'er' in the end of any word"},
'Mosco':{'country':'Ruassia','population':'7000000000','a fact':'Vodka!'}
}
for i,j in cities.items():
print(i+':\n'+'Country:\t'+j['country']+'\nPopulation:\t'+j['population']+'\nA fact:\t\t'+j['a fact']+'\n')

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: