question = ""
while question not in questionList:
question = questionList.append(input("Whats your question? "))
if question in questionList:
break
elif question == "none":
break
我想做的是让用户反复问一个问题,直到输入“无”或直到他们重复自己为止。他们输入的内容应该放入“ questionList”列表中,唯一的问题是我的代码无论如何都不会中断。如何使while循环中断?
question = "_"
questionList=[]
while question != "":
question = str(input("Whats your question? "))
if question == None or question in questionList:
break
questionList.append(question) # returns None
questionList.append()
总是返回None
,而您的代码似乎假定它返回了其参数。改写如下: