Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def takeText():
- return input("Say sth (or type bye to quit): ").lower()
- def respondAndCheck(text):
- for index in range(len(keywords)):
- if (keywords[index] in text):
- print("Bot: " + responses[index])
- return True
- return False
- def appendKeywordIfDoesNotExists(exists):
- if (exists == False):
- newKeyword = input("I'm not sure how to respond... Please provide a keyword: ")
- keywords.append(newKeyword)
- newResponse = input("How I should respond to " + newKeyword + "? ")
- responses.append(newResponse)
- greetings = ["Hello", "What's up?", "Howdy!"]
- goodbyes = ["Bye!", "Goodbye!", "See you soon!"]
- keywords = ["music", "pet", "book"]
- responses = ["music is relaxing!", "pets are so sweet!", "books are interesting!"]
- print("Bot: " + random.choice(greetings))
- while (1):
- text = takeText()
- if (text == "bye"):
- break
- exists = respondAndCheck(text)
- appendKeywordIfDoesNotExists(exists)
- print(random.choice(goodbyes))
Add Comment
Please, Sign In to add comment