そこで、Pythonで短くてシンプルなチャットボットを作成しましたが、苛立たしい問題があります。プログラムはposResponses()
最初に関数を呼び出すだけです。
コンテキストでは、最初の質問に「悲しい」、「ひどい」、さらには「asdfasdfasdf」で答えた場合でも、肯定的な応答が得られます。
ネガティブ/あいまいなキーワードを入力すると、negResponses()
/ambiguousResponses()
関数が呼び出されます。そうではありません。私は何を間違えましたか、そしてどのようにそれを修正しますか?コードは次のとおりです。
import random
import time
def opening():
print('Hello!')
def responseType():
responseType = str(input('How are you ?'))
if responseType == 'good' or 'great' or 'fantastic' or 'decent' or 'fine' or 'ok' or 'okay': posResponses()
elif responseType == 'bad' or 'terrible' or 'sad' or 'grumpy' or 'angry' or 'irritated' or 'tired': negResponses()
else: ambiguousResponses()
def posResponses():
number = random.randint(1, 4)
if number == 1:
print('That\'s great! So what\'s up?')
input()
ambiguousResponses()
if number == 2:
print('Really? I\'d like to hear more.')
input()
ambiguousResponses()
if number == 3:
print('I\'m glad to hear that. What\'s going on?')
input()
ambiguousResponses()
if number == 4:
print('Ah, me too. You should begin a topic discussion.')
input()
ambiguousResponses()
def negResponses():
number2 = random.randint(5, 8)
if number2 == 5:
print('That\'s really too bad. Care to elaborate?')
input()
ambiguousResponses()
if number2 == 6:
print('Awww. Why?')
input()
ambiguousResponses()
if number2 == 7:
print('That sucks! How come?')
input()
ambiguousResponses()
if number2 == 8:
print('What a shame! You should explain why.')
input()
ambiguousResponses()
def ambiguousResponses():
number = random.randint(1, 4)
if number == 1:
print('Interesting. Carry on.')
input()
ambiguousResponses()
if number == 2:
print('Wow, elaborate!')
input()
ambiguousResponses()
if number == 3:
print('What an astute remark! Continue.')
input()
ambiguousResponses()
if number == 4:
print('How interesting. Please do explain further.')
input()
ambiguousResponses()
if __name__ == "__main__":
opening()
responseType()