码迷,mamicode.com
首页 > 其他好文 > 详细

7-4__7-7练习

时间:2017-12-09 20:46:15      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:app   div   提示   prompt   ima   rom   enter   ase   ice   

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‘]

 

7-4__7-7练习

标签:app   div   提示   prompt   ima   rom   enter   ase   ice   

原文地址:http://www.cnblogs.com/jdy113/p/8012368.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!