{}
A Python course that doesn't leave you guessing. See every step with our code visualizer.
Try it yourself!
A Python course that doesn't leave you guessing. See every step with our code visualizer.
Try it yourself!
run-icon
main.py
# file: chatbot.py def get_response(user_input): user_input = user_input.lower().strip() responses = { "hello": "Hi there! How can I help you?", "hi": "Hello! What can I do for you?", "help": "I'm a simple chatbot. Try saying 'hello', 'how are you', or 'bye'.", "how are you": "I'm just a bot, but I'm doing fine!", "bye": "Goodbye! Have a nice day!" } # Search for exact match if user_input in responses: return responses[user_input] else: return "I'm not sure how to respond to that." def run_chatbot(): print("SimpleChatBot: Type something to begin (say 'bye' to exit)") while True: user_input = input("You: ") response = get_response(user_input) print("Bot:", response) if user_input.lower().strip() == "bye": break if __name__ == "__main__": run_chatbot()
Output