您的位置:首页 > 其它

高级变成技术作业 (六)

2018-03-21 22:06 162 查看
6-1 人 :使用一个字典来存储一个熟人的信息,包括名、姓、年龄和居住的城市。该字典应包含键first_name 、last_name 、age 和city 。将存储在该字典中的每项信息都打印出来。

information = {"first_name":"hongchen","last_name":"yang","age":'27','city':'guangdong'}print (information)

6-5 河流 :创建一个字典,在其中存储三条大河流及其流经的国家。其中一个键—值对可能是'nile': 'egypt' 。
使用循环为每条河流打印一条消息,如“The Nile runs through Egypt.”。
使用循环将该字典中每条河流的名字都打印出来。

使用循环将该字典包含的每个国家的名字都打印出来。

River_country = {'Nile':'Sudan','the changjiang river':'China','amazon river':'Brazil'}for river,country in River_country.items(): print("The " + river + " run through " + country)for river in River_country.keys(): print (river)for country in River_country.values(): print(country)

6-7 人 :在为完成练习6-1而编写的程序中,再创建两个表示人的字典,然后将这三个字典都存储在一个名为people 的列表中。遍历这个列表,将其中每个人的所有信息都打印出来。

information_1 = {'first_name':'yuanhao','last_name':'zou','age':'23','city':'jiangxi'}information_2 = {'first_name':'hongyang','last_name':'chen','age':'24','city':'guangdong'}information_3 = {'first_name':'xinrui','last_name':'chen','age':'24','city':'changsha'}all_information = [information_1,information_2,information_3]for value in all_information: print(value)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  homework