在Jupyter Notebook外运行时出现代码错误

时间:2019-07-20 12:32:23

标签: python jupyter-notebook project chatbot

我正在用Python创建一个非常基本的,基于文本的聊天机器人程序(这是自通过在线课程学习以来的第一个程序),该程序可以处理各种用户输入。我正在使用Jupiter Notebook和我的终端对我自己的代码进行故障排除。但是,代码在Jupyter中运行,但不在我自己的终端中运行。

我已经尝试了自己的终端和在线课程的终端,但是在response ==上一直遇到错误,但这也许是因为我还没有完全了解它的细微差别,所以也许就是问题所在。 / p>

def cs_service_bot():
    print("Hello! I'm the chatbot here! Welcome to my services. Are you a new or existing user?\n\n")
    response = input('Please enter the number corresponding to your choice: ')
    if response == 1:
        new_customer()
    elif response == 2:
        existing_customer()
    else:
        print("Sorry, I didn't understand your choice.")

应该运行,但代码在if response == 1:处跳出,依此类推。

1 个答案:

答案 0 :(得分:1)

input() returns a string,您正在与整数进行比较。

尝试:

print("Hello! I'm the chatbot here! Welcome to my services. Are you a new or existing user?\n\n")
response = input('Please enter the number corresponding to your choice: ')
if response == "1":
    new_customer()
elif response == "2":
    existing_customer()
else:
    print("Sorry, I didn't understand your choice.")
相关问题