+ 2

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!

1st Apr 2019, 8:23 PM
Silvio Petix
Silvio Petix - avatar
2 ответов
+ 8
It 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
1st Apr 2019, 8:48 PM
Anna
Anna - avatar
+ 2
Thanks
1st Apr 2019, 8:50 PM
Silvio Petix
Silvio Petix - avatar