这是一个门外汉记的笔记~
1、使用break退出循环,并不输出‘quit’
#循环:用户的比萨表,quit结束循环
prompt = "Please input the toppings you want: "
prompt += "\nEnter 'quit' to close."
message = ""
while message != 'quit':
message = input(prompt)
if message == 'quit':
break
print(f"You want {message.title()}")
2、条件测试退出循环,并不输出‘quit’
#循环:用户的比萨表,quit结束循环
prompt = "Please input the toppings you want: "
prompt += "\nEnter 'quit' to close."
message = ""
while message != 'quit':
message = input(prompt)
if message != 'quit':
print(f"You want {message.title()}")
3、flag退出循环,并不输出‘quit’
#循环:用户的比萨表,quit结束循环
prompt = "Please input the toppings you want: "
prompt += "\nEnter 'quit' to close."
active = True
while active:
message = input(prompt)
if message != 'quit':
print(f"You want {message.title()}")
else:
active = False