2017-06-20 32 views
0

我对Python很新,我正在无限循环中挣扎。看来这应该工作,因为用户输入不是,但它只是杀死该程序。有条件的无限python循环

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

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

你瞬间打破了while循环,而不关注用户的输入。 – asongtoruin

+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