题目链接:
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)))
打印结果: 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.
参考答案链接