Page 388 - AI_Ver_3.0_class_11
P. 388
Program 2: Create a simple chatbot using Python:
def get_response(user_input):
if "hello" in user_input.lower():
return "Hi there! How can I help you?"
elif "how are you" in user_input.lower():
return "I'm just a bot, but I'm here to help you!"
elif "bye" in user_input.lower():
return "Goodbye! Have a nice day!"
elif "what is your name" in user_input.lower():
return "I'm a simple chatbot created to assist you."
elif "what can you do" in user_input.lower():
return "I can respond to simple greetings and questions. Try asking me something!"
else:
return "I'm sorry, I don't understand."
def main():
print("Welcome to the Simple Chatbot!")
print("Type 'bye' to exit.")
while True:
user_input = input("You: ")
if user_input.lower() == 'bye':
print("Chatbot: Goodbye! Have a nice day!")
break
else:
response = get_response(user_input)
print("Chatbot:", response)
if __name__ == "__main__":
main()
Output:
Welcome to the Simple Chatbot!
Type 'bye' to exit.
You: hello
Chatbot: Hi there! How can I help you?
You: how are you
Chatbot: I'm just a bot, but I'm here to help you!
You: what can you do
Chatbot: I can respond to simple greetings and questions. Try asking me something!
You: bye
Chatbot: Goodbye! Have a nice day!
386 Touchpad Artificial Intelligence (Ver. 3.0)-XI

