《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)