python - 无法运行Python脚本

标签 python compiler-errors

这是我的代码:

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/

相关文章:

iphone - 用于二进制 plist 的 Python 模块

c++ - 从基调用派生类的虚函数导致 "not a member"错误

c - linux/ext2_fs.h 有什么问题?

c++ - 我可以将 C/C++ #defines 设为私有(private)吗?

Java 错误;需要数组,但找到了 java.lang.String

python - 使用 PyParsing 解析 Python 代码?

python - 从常规网格数据库创建波前 .obj 文件

python - 为什么在尝试绘制散点图时出现 KeyError?

python - MatPlotLib——对象的大小

c# - Unity重复生成,未使用的生成位置,问题