7-4__7-7练习

大憨熊 提交于 2019-12-26 02:19:18

7-4 比萨配料 :编写一个循环,提示用户输入一系列的比萨配料,并在用户输入'quit' 时结束循环。每当用户输入一种配料后,都打印一条消息,说我们会在比萨 中添加这种配料。

prompt = "\nPlease enter your choice of pizza ingredients: "
prompt += '\nEnter "quit" to end the program. '

ingredients = []
active = True
while active:
    message = input(prompt)
    if message == 'quit':
        active = False
    else:
        print("We will add the " + message.title() + " to your pizza.")
        ingredients.append(message.title())
print(ingredients)
运行结果如下:
Please enter your choice of pizza ingredients: 
Enter "quit" to end the program. pepper
We will add the Pepper to your pizza.

Please enter your choice of pizza ingredients: 
Enter "quit" to end the program. pepperoni
We will add the Pepperoni to your pizza.

Please enter your choice of pizza ingredients: 
Enter "quit" to end the program. quit
['Pepper', 'Pepperoni']

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!