Check if Palindrome

class practiceYln():
    def __init__(self):  # 类参数的初始化
        self.text = None

    def checkifpalindrome(self):
        self.text = input('please input a word:')  # input用来接收输入
        if self.text == ''.join(reversed(self.text)):  # 先反转字符串再拼接
            print('yes, this word is a palindrome.')
        else:
            print('no, this word is not a palindrome.')


#调用:
tt = practiceYln()
tt.checkifpalindrome()

#结果是: 
please input a word:big
no, this word is not a palindrome.

please input a word:racecar
yes, this word is a palindrome.

 

posted @ 2020-03-27 11:48  YlnChen  阅读(118)  评论(0编辑  收藏  举报