#7-5 电影票
prompt = "\n请输入观众的年龄:"
prompt += "\n输入'quit'来结束程序。"
age = ""while age != 'quit':
age = input(prompt)
if age != 'quit':
age = int(age)
if age < 3:
print("观众免费,票价为0美元。")
elif age < 12:
print("票价为10美元。")
elif age >= 12:
print("票价为15美元。")
elif age != 'quit':
print(age)
#7-8 熟食店
sandwich_orders = ['tuna','chess','beef']
finished_sandwiches = []
while sandwich_orders:
current_sandwich = sandwich_orders.pop()
print("I made your " + current_sandwich + " sandwich.")
finished_sandwiches.append(current_sandwich)
print("所有的三明治如下:")
for sandwich in finished_sandwiches:
print(sandwich.title())
7-9 五香烟熏牛肉(pastrami)卖完了
#7-9 五香烟熏牛肉(pastrami)卖完了
sandwich_orders = ['tuna','chess','beef','pastrami','pastrami','pastrami',]
finished_sandwiches = []
print("熟食店的五香烟熏牛肉卖完了。")
while'pastrami'in sandwich_orders:
sandwich_orders.remove('pastrami')
while sandwich_orders:
current_sandwich = sandwich_orders.pop()
print("I made your " + current_sandwich + " sandwich.")
finished_sandwiches.append(current_sandwich)
print("所有的三明治如下:")
for sandwich in finished_sandwiches:
print(sandwich.title())
7-10 梦想的度假胜地
#7-10 梦想的度假胜地
lists = {}
active = True
while active:
#提示输入被调查者的名字和回答name = input("\nWhat's your name?")
list = input("If you could visit one place in the world, where would you go?")
#将答案存储在字典中
lists[name] = listrepeat = input("Would you like to let another person respond?(yes/no)")
ifrepeat == 'no':
active = False
#调查结束,显示结果
print("\n下面是调查结果:")
forname,listin lists.items():
print(name + " would like to go " + list + ".")