Wikipedia:Sandbox
Welcome to this sandbox page, a space to experiment with editing.
You can either edit the source code ("Edit source" tab above) or use VisualEditor ("Edit" tab above). Click the "Publish changes" button when finished. You can click "Show preview" to see a preview of your edits, or "Show changes" to see what you have changed. Anyone can edit this page and it is automatically cleared regularly (anything you write will not remain indefinitely). Click here to reset the sandbox. You can access your personal sandbox by clicking here, or using the "Sandbox" link in the top right.Creating an account gives you access to a personal sandbox, among other benefits. Do NOT, under any circumstances, place promotional, copyrighted, offensive, or libelous content in sandbox pages. Doing so WILL get you blocked from editing. For more info about sandboxes, see Wikipedia:About the sandbox and Help:My sandbox. New to Wikipedia? See the contributing to Wikipedia page or our tutorial. Questions? Try the Teahouse! |
Here is some source code for an AI:
import random greetings = [(you can add how much you want)] print(random.choice(greetings)) goodbyes = [ditto.]
- 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()