高级编程技术课后作业 第六章练习

6-2 喜欢的数字

代码:

favorite_num = {"Amy": 1, "John": 2, "Lily": 2, "Mike": 5, "Tom": 3}
for name, num in favorite_num.items():
    print(name + " is fond of " + str(num))
 

结果:

Amy is fond of 1
John is fond of 2
Lily is fond of 2
Mike is fond of 5

Tom is fond of 3


6-5 河流

代码:

rivers = {"Nile": "Egypt", "Abc": "Def", "Mccp": "Ame"}

for river, country in rivers.items():
    print(river + " runs through " + country)

for river in rivers.keys():
    print(river)

for country in rivers.values():
    print(country)
 

结果:

Nile runs through Egypt
Abc runs through Def
Mccp runs through Ame
Nile
Abc
Mccp
Egypt
Def

Ame


6-10 喜欢的数字们

代码:

favorite_nums = {"Amy": [1, 2, 5], "John": [2, 7, 9], "Lily": [2, 4], "Mike": [5, 8, 9], "Tom": [3]}
for name, nums in favorite_nums.items():
    print(name + " is fond of " + str(nums))
 

结果:

Amy is fond of [1, 2, 5]
John is fond of [2, 7, 9]
Lily is fond of [2, 4]
Mike is fond of [5, 8, 9]

Tom is fond of [3]







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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值