#設(shè)置需要過慮的標(biāo)點(diǎn)符號(hào) forbidden = (".", "?", "!", ":", ";", "-", "—", "()", "[]", "...", "'", '""', "/", ",", " ") #獲取一個(gè)字符串,書中要求確認(rèn)"Rise to vote, sir."是回文 text = input("請(qǐng)輸入:") #將字符串倒過來 def reverse(text): str_tmp = [] str = "" for i in range(0,len(text)): if text[i] in forbidden: continue else: str_tmp.append(text[i].lower())#方便比較,將字母轉(zhuǎn)成小寫字母 return str.join(str_tmp)[::-1] #做是否是回文檢測(cè) def is_palindrome(text): str_tmp = [] str = "" for i in range(0,len(text)): if text[i] in forbidden: continue else: str_tmp.append(text[i].lower()) return str.join(str_tmp) == reverse(text) #
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com