Hello i'm new in python and im stuck with this error. Can you explain me what am i doing wrong? Also is the math import necessary?
The consept is to find if the word is palindrome.
Here is my code:
#palindrome
import math #do i need it?
wrd=input("give me a word ")
key=False
length=int(len(wrd)/2 +1)
for i in length:
for j in length:
if i==j:
pass
else:
key=True
if key==False: print("palindrome")
else: print("not palindrome")
You do not need to import math
Use range()
function -
wrd=input("give me a word ")
key=False
length=int(len(wrd)/2 +1)
for i in range(length):
for j in range(length):
if wrd[i]==wrd[j]:
pass
else:
key=True
if key==False: print("palindrome") # This is generally bad practice
else: print("not palindrome") # Use indentation so that it is more readable