标题三个出口
7-6 三个出口:以另一种方式完成练习-4或练习-5,在程序中采取如下所有做法。
·在while循环中使用条件测试来结束循环。
·使用变量active来控制循环结束的时机。
·使用break语句在用户输入’quit’时退出循环。
#coding=utf-8
prompt = "Please enter the pizza toppings. To finish,please enter 'quit'.\n"
'''
#1.break
while True:
toppings = input(prompt)
if toppings == 'quit':
break
else:
print("We're going to add %s to the pizza.\n"%toppings)
'''
'''
#2.条件测试
toppings = ''
while toppings!='quit':
toppings = input(prompt)
if toppings!= 'quit':
print("We're going to add %s to the pizza.\n"%toppings)
'''
#active控制循环
active = Truewhile active:
toppings = input(prompt)
if toppings == 'quit':
active = False
else:
print("We're going to add %s to the pizza.\n"%toppings)