0% found this document useful (0 votes)
6 views

Test1 Copy 5

The document contains a Python script for a simple chatbot that responds to user inputs based on predefined patterns. It uses regular expressions to match user queries and provides appropriate responses, including greetings and farewells. The chatbot continues to interact with the user until the user types 'bye'.

Uploaded by

maximorero14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Test1 Copy 5

The document contains a Python script for a simple chatbot that responds to user inputs based on predefined patterns. It uses regular expressions to match user queries and provides appropriate responses, including greetings and farewells. The chatbot continues to interact with the user until the user types 'bye'.

Uploaded by

maximorero14
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import re

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()

You might also like