Ad

How Can I Add N User Inputs Into A List Using A While Loop?

- 1 answer

question = ""
while question not in questionList:
    question = questionList.append(input("Whats your question? "))
    if question in questionList:
        break
    elif question == "none":
        break

What I am trying to do is to have the user ask a question repeatedly until either input "none" or until they repeat themselves. The things they input should go into the "questionList" list The only problem is that my code doesn't break no matter what. How can I get the while loop to break?

Ad

Answer

question = "_"
questionList=[]
while question != "":
    question = str(input("Whats your question? "))
    if question == None or question in questionList:
        break
    questionList.append(question) # returns None
Ad
source: stackoverflow.com
Ad