Python入门习题大全——比萨配料

Python入门习题大全——索引

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

# 比萨配料
prompt = "Please add something: "
prompt += "\n(Enter 'quit' when you finished.)\n"
active = True
while active:
    sth = input(prompt)
    if sth == 'quit':
        active = False
    else:
        print("\nWe'll add it!\n")

输出为:
(依次输入 a,b,quit)

Please add something: 
(Enter 'quit' when you finished.)
a

We'll add it!

Please add something: 
(Enter 'quit' when you finished.)
b

We'll add it!

Please add something: 
(Enter 'quit' when you finished.)
quit

Process finished with exit code 0
发布了269 篇原创文章 · 获赞 18 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_43479432/article/details/105420810