題目鏈接:
http://www.pythonchallenge.com/pc/def/map.html 由于僅僅是第二道題,所以題目還是很易懂的,按圖片中的指示,將每個字母替換成它在字母表中順延兩位的那個字母就可以了,解答如下:、
def trans(char):
'''Translate a letter as the one two places after it'''
if char.isalpha():
return chr((ord(char)- ord('a') + 2)%26 + ord('a'))
return char
if __name__ == '__main__':
text = '''g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. '''
print(''.join(map(trans, text)))
打印結(jié)果: i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.
參考答案鏈接