File “<string>”, line 1, in <module> NameError: name ' ' is not defined in ATOM [duplicate]

人盡茶涼 提交于 2020-05-15 09:45:08

问题


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

Here is my code

# -*- 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 : ")

回答1:


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.

In python 2, input results in your code looking for a definition for your input, rather than taking it as a string.



来源:https://stackoverflow.com/questions/52567471/file-string-line-1-in-module-nameerror-name-is-not-defined-in-atom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!