【发布时间】:2020-10-14 15:34:42
【问题描述】:
我正在尝试实现一个程序,我想在其中检查一旦达到桌椅数量限制的标准,循环应该中断并打印最终的打印语句。从逻辑上讲,在第一个 break 语句之后,它会从第一个 for 循环中中断,但不会中断完整的 for 循环并打印最终语句并继续迭代。
我希望那些桌子或椅子达到最大数量,循环应该中断。
知道如何修改吗?如果可以,我可以实现 while 语句吗?如何实现?
我是 python 新手,发现这些练习很有趣,你的帮助会很大。
#variables
number_of_tables = 200
no_of_chairs = 500
for tables in range(0, number_of_tables):
for chairs in range(0, no_of_chairs):
prompt = "Bienvenue a la'restaurant"
answer = input("Please enter for how many people you need a table: ")
print(f"Welcome family of {answer}, please wait while we take you to your seat")
number_of_tables -= 1
no_of_chairs -= int(answer)
if number_of_tables == 0 or no_of_chairs == 0:
reply = "Good things need patience. We are full. Please wait in the lobby till a table gets empty. We thank you for understanding"
print(reply)
break;
print("Thank you for visiting us.")
【问题讨论】:
标签: python python-3.x for-loop