0

I am making a chatbot that i want to do a survey. How can i do several requests in order to send a question(Q1) and get answer(A1) and after it get's the right answer to make Q2 and so on.

I was thinking something like:

bot_send = "Q1: From 1 to 10 how you feel?"
while answer <> (of the format i want):
   bot_send = 'Please insert a valid value!
store_answer1
bot_send = Q2: From 1 to 10 ....?
.
.

I have used Python! I have already created a normal chatbot that answers in questions, but it can't handle a questionnaire-survey.

Any help would be high appreciated! Thank you!

LaSanton
  • 127
  • 9

1 Answers1

0

You can nest a while loop in a for loop. Create a list of questions and loop through each question.

Inside the for loop, write a while loop to get an input for the question and loop until the input is valid. Since this is a survey, I imagine the valid answers would be a multiple choice, but you can write a isValid function to check the input.

questions = ["question1\n", "question2\n", "question3\n", ...]
for question in questions:
    while True:
        answer = input(question)
        if isValid(answer):
            # store answer
            break
KKJ
  • 87
  • 4