Untitled
import random def get_response(user_input): responses = { "hello": ["Hi there!", "Hello! How can I help you today?"], "how are you": ["I'm just a program, but I'm doing great!", "I'm here and ready to assist you!"], "bye": ["Goodbye! Have a great day!", "See you later!"] } user_input = user_input.lower() for key in responses: if key in user_input: return random.choice(responses[key]) return "Sorry, I don't understand that." def chat(): print("Hello! I'm your chatbot. Type 'bye' to end the chat.") while True: user_input = input("You: ") if user_input.lower() == "bye": print("Chatbot: Goodbye! Have a great day!") break response = get_response(user_input) print(f"Chatbot: {response}") if __name__ == "__main__": chat()
Leave a Comment