<p>我正在尝试制作一个程序来检查一个单词是否是回文,目前为止我已经做了很多,并且它可以处理有偶数个数字的单词。如果字母的数量是奇数,我知道怎么做,但我就是不知道如何找出一个数字是奇数。有什么简单的方法可以找到一个数是奇数还是偶数吗?</p>
<p>仅供参考,这是我的代码:</p>
<pre><code>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()
</code></pre>
<p>谢谢</p>