“如何修复”;“字符串反转”;python代码?

“如何修复”;“字符串反转”;python代码?,python,Python,我的字符串反转代码可以在其他网站上使用,但不能在我的vim ubuntu机器上使用 wrd=input("Please enter a word ") wrd=str(wrd) rvs=wrd[::-1] print(rvs) if wrd == rvs: print("This word is a palindrome") else: print("This word is not a palindrome")

我的字符串反转代码可以在其他网站上使用,但不能在我的vim ubuntu机器上使用

   wrd=input("Please enter a word ")
    wrd=str(wrd)
    rvs=wrd[::-1]
    print(rvs)
    if wrd == rvs:
        print("This word is a palindrome")
    else:
        print("This word is not a palindrome")

它给出了错误:

python hannah1.py
Please enter a word hannah
Traceback (most recent call last):
  File "hannah1.py", line 1, in <module>
    wrd=input("Please enter a word")
  File "<string>", line 1, in <module>
NameError: name 'hannah' is not defined
python hannah1.py
请输入一个单词hannah
回溯(最近一次呼叫最后一次):
文件“hannah1.py”,第1行,在
wrd=输入(“请输入一个单词”)
文件“”,第1行,在
NameError:未定义名称“hannah”

您必须使用
原始输入:

wrd=raw_input("Please enter a word")
rvs=wrd[::-1]
print(rvs)
if wrd == rvs:
    print("This word is a palindrome")
else:
    print("This word is not a palindrome")
现在它可以工作了,Python2中的
input
与Python3中的
eval(input(…)
相同,但是它将尝试查找名为
hannah
的变量,而没有任何名为
hannah
的变量