测验六python编程题,Python编程第六章习题.py

# 习题6-1 使用一个字典 存信息打出来

durian_mille_crepe_cake={'durian':'炒了',

'mille crepe':'煎了',

'cake':'抹上',

}

print(durian_mille_crepe_cake)

# 习题6-2

favorite_number={'a':1,'b':2,'c':3,'d':4,'e':5}

print(favorite_number)

# 习题6-3

python_words={'Code lay out':'代码布局',

'Whitespaces in Expressions':'表达式中的空格',

'Comments':'注释',

'Naming Conventions':'命名规范',

'programming recommendations':'编程建议'}

# .items()不要忘,为了调用字典中的值

for word, explaination in python_words.items():

print("\n"+word+":")

print(explaination)

# 6-3 python专业词汇字典

python_words={'Code lay out':'代码布局',

'Whitespaces in Expressions':'表达式中的空格',

'Comments':'注释',

'Naming Conventions':'命名规范',

'programming recommendations':'编程建议',

'Global Variable Names':'全局变量名',

'Function Annotation':'功能注释',

'Indentation':'缩进',

'Binary Operator':'运算符',

'String quotes':'字符串引号'

}

# 习题6-4

for word, explaination in python_words.items():

print("\n"+word+":")

print(explaination)

# 6-5 河流 国家

rivers={'La Seine':'France','yellow river':'China','Nile':'Egypt'}

for river, country in rivers.items():

print("\nThe "+river.title()+" runs through "+country+'!!')

for river, country in rivers.items():

print(river)

for river, country in rivers.items():

print(country)

# 6-6 名单列表,字典,在列表中不在列表中区别打印

king_seven_armed_sea=['鹰眼','老沙','九蛇','明哥','甚平','月光莫利亚','熊','罗','巴基']

the_defeated={'老沙':'歇菜','月光莫利亚':'完蛋','熊':'打不过跑','甚平':'收编'}

for name in king_seven_armed_sea:

if name in the_defeated.keys():

print(name+',嘿兄弟老熟人了啊')

else:

print(name,',你等着')

# 6-7 三个字典合成一个字典

durian_mille_crepe_cake={'durian':'炒了',

'mille crepe':'煎了',

'cake':'抹上',

}

tomato_egg={'tomato':'切了',

'egg':'炒了',

'suger':'适量',

'salt':'适量'}

palace_exploded_chicken_man={'peanut':'爆炒',

'chicken':'腌好',

'carrot':'切丁'}

cook_books=[durian_mille_crepe_cake,

tomato_egg,

palace_exploded_chicken_man,

]

for dish in cook_books:

for ingredient, method in dish.items():

print("\n材料:"+ingredient+":")

print("方法:"+method)

# 6-8 宠物

tom={'type':'cat','host':'一个只有脚出境的女的'}

jerry={'type':'耗子','host':'观众'}

speike={'type':'dog','host':'一个只有脚出境的女的'}

pets=[tom,jerry,speike]

for pet in pets:

for key, value in pet.items():

print('\n'+key+":"+value)

# 6-9 喜欢的地方,字典套列表{'':[]}

favorite_places={'依萍':['大上海','可云家','火车站'],

'如萍':['书桓家','公园','上海大桥'],

'陆飞':['如萍学校','报社','战场'],

}

for name, places in favorite_places.items():

print("\n"+name+'喜欢的地方:')

for place in places:

print(place)

# 6-10 喜欢的数字

favorite_number={'a':[1,2,3],

'b':[4,5,6],

'c':[7,8,9],

'd':[10,11,12],

'e':[13,14],

}

for name, numbers in favorite_number.items():

print("\n"+name+"喜欢的数字是:")

for number in numbers:

print(number)

# 6-11 城市 字典套字典a={'a':{}}

# bordeux={'country':'france',

# 'population':243636,

# 'fact':'水镜广场比特沙丘',

# }

#

# larochelle={'country':'france',

# 'population':100000,

# 'fact':'港口水族馆海贼梦世界尽头的灯塔',

# }

#

# barcelona={'country':'spain',

# 'population':1610000,

# 'fact':'建筑教堂佛朗明哥圆圈舞水果海鲜管够',

# }

# places={bordeux,larochelle,barcelona}

places={'bordeux':{

'country':'france',

'population':'243636',

'fact':'水镜广场比特沙丘',

},

'larochelle':{

'country':'france',

'population':'100000',

'fact':'港口水族馆海贼梦世界尽头的灯塔',

},

'barcelona':{'country':'spain',

'population':'1610000',

'fact':'建筑教堂佛朗明哥圆圈舞水果海鲜管够',

},

}

for city, info in places.items():

print("\n\n"+city+'介绍:')

for key, value in info.items():

print('\n'+key+':'+value)

# 6-12 扩展,不多行了,你以为我真的会去做吗,过

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值