+ 2
Why does this not work?
2 Réponses
+ 3
Try it like this:
if len(x) % 2 == 0:
len(x) % 1 is always 0.
+ 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) + "'.")