while循环 动手试一试
1.创建一个三明治列表,其中包含各种三明治名,至少保证‘pastrami’出现三次,在创建一个空列表,对每种三明治打印一条信息,比如i made your tuna sandwich,并将其移动空列表中,所有三明治制作好后,打印一条消息,将这些三明治都列出了。
orders=['Arepa','Pastrami','Croque Madame','Smoked Meat','Pastrami','Doner Kebab','Arepa','Pastrami','Tuna'] finished=[] while orders: a=orders.pop() print('I made your %s sandwich.'%(a)) finished.append(a) print(sorted(finished))
2.在开头打印一条消息,指出pastrami已经卖完了,在使用一个循环将order中的pastrami删除,确认最终的列表中不含有pastrami
orders=['Arepa','Pastrami','Croque Madame','Smoked Meat','Pastrami','Doner Kebab','Arepa','Pastrami','Tuna'] finished=[] print('Pastrami is sold out.') while 'Pastrami' in orders: orders.remove('Pastrami') while orders: a=orders.pop() print('I made your %s sandwich.'%(a)) finished.append(a) print(sorted(finished))
3.调查用户梦想度假胜地,并编写一个打印调查结果代码块
dic={} flag=True while flag: name=input('What is your name?') place=input('If you could visit one place in the world,where would you go?') dic[name]=place a=input('Anyone else? or quit') if a.lower() =='quit': flag=False for i,v in dic.items(): print(i,'want to visit',v)