问题描述
这很奇怪,因为我的代码在在线python解释器中工作正常,但是当我在Atom的Linux Mint中运行它时,输入一个字时会出现以下错误消息:
It's weird because my code works fine in online python interpreter but when I run it in linux mint with Atom, I have this error message when I enter a word:
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 : ")
推荐答案
尝试使用raw_input
而不是input
.听起来好像在在线解释器中,您可能正在Python 3中运行代码,其中input
的行为类似于Python 2的raw_input
,并在本地使用Python 2.
Try using raw_input
instead of input
. It sounds like in the online interpreter you might be running the code in Python 3, in which input
behaves like Python 2's raw_input
, and using Python 2 locally.
在python 2中,input
导致您的代码在寻找输入的定义,而不是将其视为字符串.
In python 2, input
results in your code looking for a definition for your input, rather than taking it as a string.
这篇关于在< module>中的文件“< string>"第1行, NameError:名称''未在ATOM中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!