我正在创建一个聊天机器人,当用户问它一个特定的问题时,它应该简单地回应用户,机器人会检测到它的代码,并以正确的输出作出回应。但我需要帮助解决打字错误。在
我的代码:
user_name = input('''What would you like to be called:
''')
bot_name = input('''
Now lets give you virtual bot a name:
''')
print(' ')
print(f"{'Thank you'} {user_name} {'You have just summoned a new bot named'} {bot_name}!")
print('''
You may now have the permission to talk to the bot! HV
''')
import time
time.sleep(2)
import random
l = (bot_name + ":Hello!", bot_name + ":Hi!", bot_name + ":Hello!")
random_greeting = random.choice(l)
print(random_greeting)
def openinput(input):
return print(input(f"{user_name}{':'}"))
if "how are you doing today" in openinput(input):
print({bot_name} + 'Very Well! Thank you for asking :)')
elif "hi" in openinput(input):
print('Hi!!')
else:
print("ERROR1.0: It seem's like my index doesn't answer your question.")
错误:
^{pr2}$
错误来自这样一个事实:您试图在返回print语句的函数中迭代(使用
in
)。我把它换成了基于输入的变量属性,现在它起作用了:因为这是一个聊天机器人,我很确定你也会希望在重写用户输入时循环,这样你就可以计算新的语句了。像这样:
^{pr2}$相关问题 更多 >
编程相关推荐