giganciprogramowania

ChatBot AI

Aug 12th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. greetings = ["Hello", "What's up?", "Howdy!"]
  4. goodbyes = ["Bye!", "Goodbye!", "See you soon!"]
  5.  
  6. keywords = ["music", "pet", "book"]
  7. responses = ["music is ok!", "pets are ok!", "books are ok!"]
  8.  
  9. print("Bot: " + random.choice(greetings))
  10.  
  11. while (1):
  12.     text = input("Say sth (or type bye to quit): ").lower()
  13.     if (text == "bye"):
  14.         break
  15.  
  16.     exists = False
  17.     for index in range(len(keywords)):
  18.         if (keywords[index] in text):
  19.             print("Bot: " + responses[index])
  20.             exists = True
  21.            
  22.     if (exists == False):
  23.         newKeyword = input("I'm not sure how to respond... Type keyword: ")
  24.         keywords.append(newKeyword)
  25.         newResponse = input("How I should respond to " + newKeyword + "? ")
  26.         responses.append(newResponse)
  27.  
  28. print(random.choice(goodbyes))
  29.  
Add Comment
Please, Sign In to add comment