Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 : ")
like image 379
mrNicky Avatar asked Sep 29 '18 10:09

mrNicky


People also ask

How do you fix NameError name is not defined?

The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.

Why am I getting a NameError in Python?

In Python, the NameError occurs when you try to use a variable, function, or module that doesn't exist or wasn't used in a valid way. Some of the common mistakes that cause this error are: Using a variable or function name that is yet to be defined.

How do you resolve a name error in Python?

To specifically handle NameError in Python, you need to mention it in the except statement. In the following example code, if only the NameError is raised in the try block then an error message will be printed on the console.

What is not defined in Python?

The Python "NameError: function is not defined" occurs when we try to call a function that is not declared or before it is declared. To solve the error, make sure you haven't misspelled the function's name and call it after it has been declared. Here is an example of how the error occurs.


1 Answers

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.

like image 51
samwalton Avatar answered Sep 30 '22 14:09

samwalton