小编Rya*_*ton的帖子

简单python代码中的NameError

这是一个简单的回文检查器.该代码适用于数字,但不适用于字符串.

x = str(input("Enter a number: "))
if x == x[::-1]:
    print x + " is a palindrome!"
else:
    print x + " is not a palindrome!"
Run Code Online (Sandbox Code Playgroud)

当我尝试输入字符串时,我收到此错误:

  File "palindrome.py", line 1, in <module>
    x = str(input("Enter a number: "))
  File "<string>", line 1, in <module>
NameError: name 'abba' is not defined
Run Code Online (Sandbox Code Playgroud)

python string undefined palindrome nameerror

-1
推荐指数
1
解决办法
383
查看次数

标签 统计

nameerror ×1

palindrome ×1

python ×1

string ×1

undefined ×1