Palindrom Words
x = input() print(str(x)) n=len(x) if n%2==0: for i in range(0,len(x)//2): pos =i if x[pos] != x[len(x)-(pos+1)]: print("the word is not palindrom") break print("The word is palindrom") else: for i in range(0,len(x)//2 +1): pos =i if x[pos] != x[len(x)-(pos+1)]: print("the word is not palindrom") break print("The word is palindrom") Where is the error? Thanks very much!
4/1/2019 8:23:03 PM
Silvio Petix
2 Answers
New AnswerIt will always print "The word is palindrom". You can use a variable to avoid that: palindrome = True for i in range(0,len(x)//2 +1): pos =i if x[pos] != x[len(x)-(pos+1)]: palindrome = False break if palindrome: print("The word is palindrom") else: print('no palindrom') Also, your break statements aren't indented enough. They will always break the loop in the first iteration