-
on project 3 ,codecademy AI python chabot building |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
try this: import random Define a dictionary of responsesresponses = { Define a function that takes a user input and returns a responsedef respond(user_input): Define the main function that loops until the user types "bye"def main(): Call the main function to start the chatbotif name == "main": |
Beta Was this translation helpful? Give feedback.
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…