条件无限python循环

时间:2017-06-20 09:42:31

标签: python loops

我对python很新,我正在努力进行无限循环。似乎这应该工作,因为用户输入不是,但它只是杀死程序。

    start = "no"
    while start.lower() == "no":

        start = input("Are you finished?")
        break

1 个答案:

答案 0 :(得分:2)

break无条件地中止while循环。删除它,如下所示:

start = "no"
while start.lower() == "no":
    start = input("Are you finished?")

或者,如果您想使用break,请将其设为条件:

while True:
    start = input("Are you finished?")
    if start.lower() != "no":
        break