Reputation:
I have inputs and responses.
userList:["Hi","What is my commission?","yes"]
cbList: ["Hi Magiee,How can I help you?","Would you like to know your commission?","Can you help me with NPN number?"]
I tried like below:
import pandas as pd
data=pd.read_excel("path",sheet_name='Sheet2')
print(data)
userList=data["User"].tolist()
cbList=data["CB"].tolist()
while True:
userInput=input("User:")
if userInput in userList:
print(cbList)
else:
print("Goodbye")
I am getting error:TypeError: 'str' object is not callable
.
I also tried with creating a dictionary with key and values guided by @Jammy.But I have same key with different values.It over written the last value with first value.
Please,suggest me how can i create chatbot with predefined inputs and responses are given?
Upvotes: 0
Views: 458
Reputation: 2806
One option you can do is to create a dict of list like:
import random
responses = {'Hi!': ['Hello there', 'hi man']}
default_responses = ['I dont know', 'GoodBye']
while True:
user_input = input('User:')
if user_input == 'exit':
break
print(random.choice(responses.get(user_input, default_responses)))
Explenation:
random.choice
choose a random value from a list
responses.get
trys to get value of user_input
from the dict, and if not found gets a default valuie of default_responses
while True:
user_input = input('User:')
if user_input == "What is my commission?":
user_input = input('Would you like to know your commission?')
if user_input == 'yes':
user_input = input('Can you help me with NPN number?')
and so on
Upvotes: 1