我正在尝试编写一个程序来检查一个单词是否是回文,到目前为止我已经得到了,它工作的单词有一个偶数的数字。我知道如何让它做一些事情,如果字母的数量是奇数,但我只是不知道如何找出一个数字是奇数。有没有什么简单的方法来确定一个数字是奇数还是偶数?
作为参考,这是我的代码:
a = 0
while a == 0:
print("\n \n" * 100)
print("Please enter a word to check if it is a palindrome: ")
word = input("?: ")
wordLength = int(len(word))
finalWordLength = int(wordLength / 2)
firstHalf = word[:finalWordLength]
secondHalf = word[finalWordLength + 1:]
secondHalf = secondHalf[::-1]
print(firstHalf)
print(secondHalf)
if firstHalf == secondHalf:
print("This is a palindrom")
else:
print("This is not a palindrom")
print("Press enter to restart")
input()