7-2 餐馆订位 :编写一个程序,询问用户有多少人用餐。如果超过8人,就打印一条消息,指出没有空桌;否则指出有空桌。
sum = input('How many people come here to have dinner?\n')
sum = int(sum)
if sum > 8:
print("Sorry, we don't have enough tables!")
else:
print("OK!")
7-5 电影票 、7-6:有家电影院根据观众的年龄收取不同的票价:不到3岁的观众免费;3~12岁的观众为10美元;超过12岁的观众为15美元。请编写一个循环,在其中询问用户的年龄,并指出其票价。
while True:
old = input('How old are you?(input q to quit)\n')
if old == 'q':
break
old = int(old)
if old < 3:
print('Free.\n')
elif old >= 3 and old <= 12:
print('$10\n')
elif old > 12:
print('$15\n')
7-8 熟食店 :创建一个名为sandwich_orders 的列表,在其中包含各种三明治的名字;再创建一个名为finished_sandwiches 的空列表。遍历列表sandwich_orders ,对于其中的每种三明治,都打印一条消息,如I made your tuna sandwich ,并将其移到列表finished_sandwiches 。所有三明治都制作好后,打印一条消息,将这些三明治列出来。
sandwich_orders = ['haochi', 'buhaochi', 'yibanban']
finished_sandwiches = []
while sandwich_orders:
print("I made your " + sandwich_orders[0] + " sandwich.")
finished_sandwiches.append(sandwich_orders.pop(0))
for sandwich in finished_sandwiches:
print(sandwich)