编写一个Python程序来检查刺痛是否是回文

问题描述 投票:0回答:1

回文是向后或向前读相同的单词、句子、诗句或偶数。 在 def() 函数中编写程序。还必须返回答案。

我尝试用正常的输入和输出功能来做到这一点。 def() 主题未清除

numbers palindrome
1个回答
0
投票

如果不使用函数来检查单词、数字或短语是否是回文,此代码可能会有所帮助:-

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")
© www.soinside.com 2019 - 2024. All rights reserved.