Jump to content

Wikipedia:Sandbox

From Wikipedia, the free encyclopedia
(Redirected from Wikipedia:SBOX)

Here is some source code for an AI:

import random greetings = [(you can add how much you want)] print(random.choice(greetings)) goodbyes = [ditto.]

  1. Use a dictionary to store keyword-response pairs

keyword_responses = {

   "lorem ipsum doler sit amet": "Lorem Ipsum является текст-заполнитель обычно используется в графических, печать и издательской индустрии для предварительного просмотра макета и визуальных макетах.",

(you can add more if you like) }

user = input("Say something (or type bye to quit) : ") user = user.lower() while (user != "bye"):

 keyword_found = False
 # Iterate over keywords in reverse order
 for keyword in keyword_responses:  # Iterate over the dictionary keys
   if keyword in user:
     print("name of bot: " + keyword_responses[keyword]) 
     keyword_found = True
     break  # Exit loop after finding a keyword
 if not keyword_found:
   new_keyword = input("name of bot: I am not sure how to respond. What keyword should I respond to? ")
   new_response = input("How should I respond to " + new_keyword + "? ")
   keyword_responses[new_keyword] = new_response  # Add the new pair to the dictionary
 user = input("Say something (or type bye to quit) : ")
 user = user.lower()