Python Forum
Chatbot - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Chatbot (/thread-21386.html)



Chatbot - metro17 - Sep-27-2019

import random
greetings = ['hola', 'hello', 'hi', 'Hi', 'hey!','hey']
question = ['How are you?','How are you doing?']
responses = ['Okay',"I'm fine"]
question1 = ['Install Type']
responses1 = ['AOInstall','Standalone Install']
while True:
        userInput = input(">>> ")
        if userInput in greetings:
                random_greeting = random.choice(greetings)
                print(random_greeting)
        elif userInput in question:
                random_response = random.choice(responses)
                print(random_response)     
        elif userInput in question1:
                random_response = random.choice(responses1)
        else:
                print("I did not understand what you said")
>>> hi
hey!
>>> How are you?
Okay
>>> Install Type --- > this does not give a response
>>>
I did not understand what you said
>>> Install Type
>>>


RE: Chatbot - Malt - Sep-27-2019

Executed in my Pycharm and received the output without any hassle
import random
greetings = ['hola', 'hello', 'hi', 'Hi', 'hey!','hey']
question = ['How are you?','How are you doing?']
responses = ['Okay',"I'm fine"]
question1 = ['Install Type']
responses1 = ['AOInstall','Standalone Install']
while True:
        userInput = input(">>> ")
        if userInput in greetings:
                random_greeting = random.choice(greetings)
                print(random_greeting)
        elif userInput in question:
                random_response = random.choice(responses)
                print(random_response)
        elif userInput in question1:
                print("Received question1")
                random_response = random.choice(responses1)
                print(random_response)
        else:
                print("I did not understand what you said")


Output:
>>> Install Type Received question1 AOInstall
And I'm using Python3