SHOW:
|
|
- or go back to the newest paste.
1 | import random | |
2 | ||
3 | def takeText(): | |
4 | return input("Say sth (or type bye to quit): ").lower() | |
5 | ||
6 | def respondAndCheck(text): | |
7 | for index in range(len(keywords)): | |
8 | if (keywords[index] in text): | |
9 | print("Bot: " + responses[index]) | |
10 | return True | |
11 | return False | |
12 | ||
13 | def appendKeywordIfDoesNotExists(exists): | |
14 | if (exists == False): | |
15 | newKeyword = input("I'm not sure how to respond... Please provide a keyword: ") | |
16 | keywords.append(newKeyword) | |
17 | newResponse = input("How I should respond to " + newKeyword + "? ") | |
18 | responses.append(newResponse) | |
19 | ||
20 | greetings = ["Hello", "What's up?", "Howdy!"] | |
21 | goodbyes = ["Bye!", "Goodbye!", "See you soon!"] | |
22 | ||
23 | keywords = ["music", "pet", "book"] | |
24 | responses = ["music is relaxing!", "pets are so sweet!", "books are interesting!"] | |
25 | ||
26 | print("Bot: " + random.choice(greetings)) | |
27 | ||
28 | while (1): | |
29 | text = takeText() | |
30 | if (text == "bye"): | |
31 | break | |
32 | exists = respondAndCheck(text) | |
33 | appendKeywordIfDoesNotExists(exists) | |
34 | ||
35 | print(random.choice(goodbyes)) |