第七章 动手试一试

7-1 汽车租赁:编写一个程序,询问用户要租赁什么样的汽车,并打印一条消息, 如“Let me see if I can find you a Subaru”。
7-2 餐馆订位:编写一个程序,询问用户有多少人用餐。如果超过 8人,就打印一 条消息,指出没有空桌;否则指出有空桌。
print("What kind of car would you want?\n")
print("Let me see if I can find you a {}.".format(car))

people = input("\nHow many people will have dinner?\n")
people = int(people)
print("Not enough table left." if people > 8
		else "There is a table for you.")
7-4 比萨配料:编写一个循环,提示用户输入一系列的比萨配料,并在用户输入 'quit'时结束循环。每当用户输入一种配料后,都打印一条消息,说我们会在比萨中添 加这种配料。
print("Input what you want in the pizza, end with 'quit'.")
burden = ''
while burden != 'quit':
	burden = input()
	if burden != 'quit':
		print('OK, we will add {} into your pizza.'.format(burden))
7-8 熟食店:创建一个名为 sandwich_orders 的列表,在其中包含各种三明治的名 字;再创建一个名为 finished_sandwiches 的空列表。遍历列表 sandwich_orders,对于 其中的每种三明治,都打印一条消息,如 I made your tuna sandwich,并将其移到列表 finished_sandwiches。所有三明治都制作好后,打印一条消息,将这些三明治列出来。
 7-9 五香烟熏牛肉(pastrami)卖完了:使用为完成练习 7-8 而创建的列表 sandwich_orders,并确保'pastrami'在其中至少出现了三次。在程序开头附近添加这样 的代码:打印一条消息,指出熟食店的五香烟熏牛肉卖完了;再使用一个 while 循环将 列表 sandwich_orders 中的'pastrami'都删除。确认最终的列表 finished_sandwiches 中 不包含'pastrami'。
 
 
sandwich_orders = ['pastrami', 'tuna', 'pastrami', 'pastrami', 'beaf', 'pastrami']
finished_sandwiches = []

print("Pastrami sandwich has sold out.\n")
while 'pastrami' in sandwich_orders:
	sandwich_orders.remove('pastrami')

for sandwich in sandwich_orders:
	print("I made your {} sandwich.".format(sandwich))
	finished_sandwiches.append(sandwich)
print("All done.")




猜你喜欢

转载自blog.csdn.net/ddl_xiaodichen/article/details/79710057
今日推荐