Generation

generate functionSat, 03 Dec 2022

Self learning chat bot

def learning_chat_bot(sentence): # split the sentence into a words list words = sentence.lower().split() # loop through the words to look for the keywords for word in words: if word in "hello": return "Hi, how are you?" if word in "bye": return "See you later!" if word in "thanks": return "You're welcome!" # Examples print(learning_chat_bot("Hello there!")) # "Hi, how are you?" print(learning_chat_bot("Bye!")) # "See you later!" print(learning_chat_bot("Thanks for teaching me how to code")) # "You're welcome!"

Questions about programming?Chat with your personal AI assistant