我创建了一个滑稽的治疗机器人(不严肃),它可以在一个会话中学习新单词,如果它们还不在两个列表中的话。在def-u响应中有一个else语句:
else:
print('Your emotions are too complex for me @{}"£$"${%£$')
但实际上并没有表达出来。有人知道为什么吗?你知道吗
任何建议都将不胜感激!你知道吗
编辑:人们解释说问题出在函数的“or”部分。我可以理解我需要改变它,但我不完全明白为什么。有什么想法吗?你知道吗
==========================================================================================
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')
修正你的假设。if语句中的每个表达式都必须是完整的,python不理解词法上下文,因此在
or
之后需要提供完整的语句。你知道吗相关问题 更多 >
编程相关推荐