active=True
while active!=False:age=input("输入观众年龄:")age=int(age)if age>12:print("15$")elif age>3:print("10$")elif age<=3 and age>0:print("0$")else:active=False
遍历列表sandwich_orders , 对于其中的每种三明治, 都打印一条消息, 如I made your tuna sandwich,并将其移到列表finished_sandwiches 。 所有三明治都制作好后, 打印一条消息, 将这些三明治列出来。
sandwich_orders=['a','b','c']
finished_sandwiches=[]
while sandwich_orders:sandwich=sandwich_orders.pop()print(f"I made your {sandwich} sandwich")finished_sandwiches.append(sandwich)
for a in finished_sandwiches:print(a)
sandwich_orders=['pastrami','a','pastrami','b','c','pastrami']
finished_sandwiches=[]
print('pastrami'+"卖完了")
while 'pastrami'in sandwich_orders:sandwich_orders.remove('pastrami')
while sandwich_orders:sandwich=sandwich_orders.pop()print(f"I made your {sandwich} sandwich")finished_sandwiches.append(sandwich)
for a in finished_sandwiches:print(a)
练习7-10 梦想的度假胜地 : 编写一个程序, 调查用户梦想的度假胜地。
使用类似于“If you could visit one place in the world, where would you go?”的提示, 并编写一个打印调查结果的代码块.
travel={}
ends='yes'
while ends!='no':location=input("请输入想去的地方:")people=input("带哪个朋友:")travel[location]=peopleends=input("是否继续\'yes or no\'")
for m,n in travel.items():print(f"输入想去的地方:{m} 带哪个朋友:{n}")