《Python》编程从入门到实践第七章习题

这个博客介绍了Python编程中关于列表和字典的实用操作。首先展示了如何使用pop()方法从sandwich_order列表中制作三明治,并打印制作过程。接着,处理包含重复元素的列表,尤其是移除所有'pastrami'三明治的过程。最后,通过用户输入创建了一个字典locations,记录了人们的梦想旅游目的地,并提供了查询功能。
摘要由CSDN通过智能技术生成

《Python》编程从入门到实践第七章习题

习题7-8

sandwich_order=['Doner Kebab','Vegemit','Cemita']
finished_sandwich=[]
while sandwich_order:
   a=sandwich_order.pop()
   print('I made your '+ a.title()+' sandwich')
   finished_sandwich.append(a)
print('\t')
for sandwich in finished_sandwich:
   print(sandwich)

习题7-9

sandwich_order=['Doner Kebab','pastrami','Vegemit','pastrami','Cemita','pastrami']
print('所有pastrami三明治都卖完了!\n')
while 'pastrami' in sandwich_order:
	sandwich_order.remove('pastrami')
print('这些是剩下的:')
for a in sandwich_order:
	print(a.title())

习题7-10

locations={}
test_1=True
while test_1:
  name=input('请输入你的名字:')
  location=input('请输入你梦想的旅游圣地:')
  locations[name]=location
  repeat=input('调查是否继续?请输入yes/no\n')
  if repeat=='no':
	  test_1=False
print('\t')
for name , location in locations.items():
	print('名字:'+name)
	print('旅游圣地:'+location)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值