这是一个简单的回文检查器.该代码适用于数字,但不适用于字符串.
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)