运行 在 Jupyter notebook 之外时出现代码错误
Code error when run outside of Jupyter notebook
我正在 Python 创建一个非常基本的基于文本的聊天机器人程序(我通过在线课程学习后的第一个程序)来处理各种用户输入。我正在使用 Jupiter notebook 和我自己的终端对我自己的代码进行故障排除。然而,代码 运行s 在 Jupyter 中,但在我自己的终端中却没有。
我已经尝试过我自己的终端和在线课程的终端,但我一直在 response ==
上收到错误,但也许是因为我还没有完全了解它的细微差别,所以这可能就是问题所在.
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:
处出错,依此类推。
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.")
我正在 Python 创建一个非常基本的基于文本的聊天机器人程序(我通过在线课程学习后的第一个程序)来处理各种用户输入。我正在使用 Jupiter notebook 和我自己的终端对我自己的代码进行故障排除。然而,代码 运行s 在 Jupyter 中,但在我自己的终端中却没有。
我已经尝试过我自己的终端和在线课程的终端,但我一直在 response ==
上收到错误,但也许是因为我还没有完全了解它的细微差别,所以这可能就是问题所在.
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:
处出错,依此类推。
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.")