回文是向后或向前读相同的单词、句子、诗句或偶数。 在 def() 函数中编写程序。还必须返回答案。
我尝试用正常的输入和输出功能来做到这一点。 def() 主题未清除
如果不使用函数来检查单词、数字或短语是否是回文,此代码可能会有所帮助:-
string = input("word, phrase or number: ")
# this step is to remove spaces and to convert characters to lower-case
sorted_string = "".join(string.split()).lower()
if sorted_string == sorted_string[:: -1]:
print("it is a palindrome")
else:
print("it is not a palindrome")