我创建了这个jokey疗法机器人(不严重),如果它们不在两个列表中,它们会在会话中学习新单词。在def learning_response中有一个else语句:
else:
print('Your emotions are too complex for me @{}"£$"${%£$')
但实际上并没有表达出来。有谁知道为什么?
非常感谢任何建议!
编辑:人们已经解释说问题出在函数的'或'部分。我可以理解我需要改变它,但不完全理解为什么。有什么想法吗?
=============================================== ============================
happy_response = ['good', 'great', 'brilliant','happy','excited','amazing']
unhappy_response = ['not good','bad','shit','unhappy','crap','low']
running = True
while running==True:
how_you = input('How are you today? ')
if how_you == 'Quit':
break
#how_scale = input('On a scale of 1-10..1 being very low, 10 being great..how are you feeling? ')
def positive_response():
print('Good. Thatll be £50 please')
def supportive_response():
print('Oh well....ever thought going skipping? That always cheers sad bot up.')
def learning_response():
happy_or = input('I dont understand. Is this a happy or unhappy response? ')
if happy_or == 'happy' or 'Happy':
happy_response.append(how_you)
print('Thank you. Love bot has learned a new positive word and become even more powerful.')
elif happy_or == 'unhappy' or 'Unhappy':
unhappy_response.append(how_you)
print('Thank you. Love bot has learned a new negative word and become even more powerful.')
else:
print('Your emotions are too complex for me @{}"£$"${%£$')
def assess_mood():
if how_you in happy_response:
positive_response()
elif how_you in unhappy_response:
supportive_response()
else:
learning_response()
assess_mood()
print('Ended...that will be £50 please')
答案 0 :(得分:0)
def learning_response():
happy_or = input('I dont understand. Is this a happy or unhappy response? ')
if happy_or == 'happy' or happy_or == 'Happy':
happy_response.append(how_you)
print('Thank you. Love bot has learned a new positive word and become even more powerful.')
elif happy_or == 'unhappy' or happy_or == 'Unhappy':
unhappy_response.append(how_you)
print('Thank you. Love bot has learned a new negative word and become even more powerful.')
else:
print('Your emotions are too complex for me @{}"£$"${%£$')
修复你的ifs。 if语句中的每个表达式都必须完整,python不理解词汇上下文,所以在or
之后你需要提供完整的语句。