zoukankan      html  css  js  c++  java
  • 7-4__7-7练习

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

    prompt = "
    Please enter your choice of pizza ingredients: "
    prompt += '
    Enter "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']
  • 相关阅读:
    python闭包&深浅拷贝&垃圾回收&with语句
    Python基本数据类型
    面向对象
    四则运算2
    周总结01
    软件工程个人作业01
    java web中乱码的种类和一些解决方式
    java web 增加信息课堂测试00
    课程00作业
    动手动脑07
  • 原文地址:https://www.cnblogs.com/jdy113/p/8012368.html
Copyright © 2011-2022 走看看