0
Find the error in the code As it always shows Not a palindrom
#Palindrom check a=str(input("Please enter a word: ")) b=list(a) l=len(a) r= " " for x in range(l-1,-1,-1): r+=b[x] c=str(r) if c==a : print("It's a palindrom.") else: print("It's not a palindrom.")
5 ответов
+ 5
I guess you know the easier test 🙂
if a == a[::-1]:
+ 3
Well the input() returns a string so the str() in line 1 is not needed.
You can directly do r+=a[x] so creating b is not necessary.
r is already a string so you don't need c=str(r).
Finally, initialize r as an empty string, not one with a space, i.e. r="", not r=" "
+ 3
Igor Kostrikin He is right on that aspect as the endpoint is excluded from the range.
+ 1
May be range(l-1,0,-1) ?