2 odpowiedzi
+ 3
Try it like this: if len(x) % 2 == 0: len(x) % 1 is always 0.
7th Feb 2018, 4:10 PM
Paul
Paul - avatar
+ 3
You can try with bitwise op. (if first bit of the length number is 1 (odd) it returns 1 (True), so the word is invalid, else it returns 0 (False), so it's valid.) if len(x) & 1: print("The word is invalid, please enter a word with an even length.") else: print("The word is '" + str(x) + "'.")
7th Feb 2018, 4:25 PM
Boris Batinkov
Boris Batinkov - avatar