Test1 Copy 5
Test1 Copy 5
patterns = {
r"hello|hi|hey": "Hello there! How can I help you?",
r"your name|who are you": "I'm a chatbot created in Python.",
r"how are you": "I'm doing well, thank you!",
r"(.*)(weather)(.*)": "Sorry, I can't check the weather right now.",
r"(.*)bye(.*)": "Goodbye! Have a great day.",
}
def chatbot_response(user_input):
user_input = user_input.lower()
for pattern, response in patterns.items():
if re.search(pattern, user_input):
return response
return "I'm not sure how to respond to that."
def main():
print("Chatbot: Hello! Type 'bye' to exit.")
while True:
user_input = input("You: ")
if "bye" in user_input.lower():
print("Chatbot: Goodbye!")
break
response = chatbot_response(user_input)
print("Chatbot:", response)
if __name__ == "__main__":
main()