首先判断一个字符串是否回文:
1 def isPlalind(s): 2 if len(s) == 1: 3 return True 4 else: 5 return s[0] == s[-1] and isPlalind(s[1:-1]) 6 7 if __name__ == ‘__main__‘: 8 while(True): 9 x = input(‘enter your string:‘) 10 print(isPlalind(x))
时间: 2024-10-25 01:09:39
首先判断一个字符串是否回文:
1 def isPlalind(s): 2 if len(s) == 1: 3 return True 4 else: 5 return s[0] == s[-1] and isPlalind(s[1:-1]) 6 7 if __name__ == ‘__main__‘: 8 while(True): 9 x = input(‘enter your string:‘) 10 print(isPlalind(x))