这很奇怪,因为我的代码在在线python解释器中可以正常工作,但是当我在Atom的linux mint中运行它时,输入一个字时我会收到此错误消息:
File "<string>", line 1, in <module>
NameError: name 'lol' is not defined
这是我的代码
# -*- coding: utf-8 -*-
word = str(input(" Enter a word : "))
reverse = word[::-1]
if reverse == word:
print("it is a palindrome, félicitation : ")
else:
print(" it is not a palindrome : ")
答案 0 :(得分:1)
尝试使用raw_input
代替input
。听起来好像在在线解释器中,您可能正在Python 3中运行代码,其中input
的行为类似于Python 2的raw_input
,并在本地使用Python 2。
在python 2中,input
导致代码在寻找输入的定义,而不是将其作为字符串。