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 : ")
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With