您的位置:首页 > 编程语言 > Python开发

python input and while循环

2018-04-01 11:30 155 查看
#7-2  餐馆订位 :编写一个程序,询问用户有多少人用餐。如果超过 8 人,就打印一条消息,指出没有空桌;否则指出有空桌。
dinnerNums = input("how many people will go to dinner?")
if int(dinnerNums)>8:
print("sorry, there is no enough disk")
else:
print('ok,please come!')
#7-4  比萨配料 :编写一个循环,提示用户输入一系列的比萨配料,并在用户输入 'quit' 时结束循环。每当用户输入一种配料后,都打印一条消息,说我们会在比萨
#中添加这种配料。
while True:
message = input("what do you want in you peasa?")
if(message == 'quit'):
break
else:
print("OK , "+message +' add to peasa')

#7-7  无限循环 :编写一个没完没了的循环,并运行它(要结束该循环,可按 Ctrl +C ,也可关闭显示输出的窗口)。
number = 10
while (number%2==0):
print(number)
number +=2
#7-8  熟食店 :创建一个名为 sandwich_orders 的列表,在其中包含各种三明治的名字;再创建一个名为 finished_sandwiches 的空列表。遍历列
#表 sandwich_orders ,对于其中的每种三明治,都打印一条消息,如 I made your tuna sandwich ,并将其移到列表 finished_sandwiches 。所有三明
#治都制作好后,打印一条消息,将这些三明治列出来。
sandwich_orders = ['beef','va','meet']
finished_sandwiches = []
while sandwich_orders:
sandwich = sandwich_orders.pop()
print("I made your "+sandwich+" sandwich ")
finished_sandwiches.append(sandwich)

for sandwich in finished_sandwiches:
print(sandwich)

#7-9  五香烟熏牛肉( pastrami )卖完了 :使用为完成练习 7-8 而创建的列表 sandwich_orders ,并确保 'pastrami' 在其中至少出现了三次。在程序开头附近添加
#这样的代码:打印一条消息,指出熟食店的五香烟熏牛肉卖完了;再使用一个 while 循环将列表 sandwich_orders 中的 'pastrami' 都删除。确认最终的列
#表 finished_sandwiches 中不包含 'pastrami' 。
sandwich_orders = ['beef',"pastrami"'va',"pastrami",'meet',"pastrami"]
print("pastrami sandwich sold out")
while 'pastrami' in sandwich_orders:
sandwich_orders.remove("pastrami")

for sandwich in finished_sandwiches:

print(sandwich)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: