gpt4 book ai didi

python - 无法运行Python脚本

转载 作者:行者123 更新时间:2023-12-02 10:49:48 25 4
gpt4 key购买 nike

这是我的代码:

name = input("What's your name? ")
print("Nice to meet you " + name + "!")

但是当我输入一个名称(例如“john”)时,它给了我这个错误:
Traceback (most recent call last):
File "name.py", line 1, in <module>
name = input("What's your name? ")
File "<string>", line 1, in <module>
NameError: name 'john' is not defined

我正在使用的python版本是“2.7.10”。

最佳答案

您需要使用raw_input而不是input,因为后者尝试评估您输入的内容,而前者则将其保留为字符串。

关于python - 无法运行Python脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31172607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com