Skip to content

Python AI chatbot is not responding to user inputs properly on responses = {} #82

Closed Answered by rakib86
andrewetm asked this question in Q&A
Discussion options

You must be logged in to vote

try this:

import random

Define a dictionary of responses

responses = {
"hello": ["Hi there!", "Hello!", "Hey!"],
"how are you": ["I'm doing well, thanks!", "I'm good. How are you?", "I'm great. How about you?"],
"what's up": ["Not much. How about you?", "Just chilling. What's up with you?", "Nothing much. You?"],
"bye": ["Goodbye!", "See you later!", "Bye!"]
}

Define a function that takes a user input and returns a response

def respond(user_input):
if user_input in responses:
return random.choice(responses[user_input])
else:
return "I'm sorry, I don't understand what you're saying."

Define the main function that loops until the user types "bye"

def main():
print("Hi, I'm a chatbot. What c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andrewetm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants