I ran the following code in a .py file (generated by Sublime Text v3126) using Terminal in Ubuntu. Ctrl+B doesn't show any errors in Sublime Text but running in Terminal yields an error. Strangely, this code worked in Terminal when it was in a previous .py file, which had other codes. Anyway, here's the particular code:
import math
import cmath
import datetime
import random as RAN
from tabulate import tabulate
def main():
print ("")
print("Key in a word.")
while True:
try:
x = str(input())
x = x.casefold()
xr = reversed(x)
print("")
print("Using iterative and/or recursive functions...")
except ValueError:
print("Invalid input. Try again")
print("")
continue
if (list(x) != list(xr)) or (x != x[::-1]):
print("The input is not a palindrome. Try again.")
print("")
continue
else:
print("The input is a palindrome.")
break
if __name__ == '__main__':
main()
So, when I run this code in a .py file containing only this code, I get this error in Terminal:
Key in a word.
example
Traceback (most recent call last):
File "./Test Pad.py", line 30 in <module>
main()
File "./Test Pad.py", line 12 in main
x = str(input())
File "<string>", line 1, in <module>
NameError: name 'example' is not defined
Thank you for your consideration.