0% found this document useful (0 votes)
7 views2 pages

Test1 Copy 3

The document contains a Python script for a simple chatbot that responds to user inputs based on predefined patterns. It includes responses for greetings, inquiries about the chatbot's identity, and a farewell message. The chatbot operates in a loop until the user types 'bye' to exit.

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)
7 views2 pages

Test1 Copy 3

The document contains a Python script for a simple chatbot that responds to user inputs based on predefined patterns. It includes responses for greetings, inquiries about the chatbot's identity, and a farewell message. The chatbot operates in a loop until the user types 'bye' to exit.

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/ 2

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