标签:
想起来之前在学校论坛上看到大神推荐的一款python游戏 Python Challenge,于是做了几道题,还很有意思。
这是第二题,先放链接:http://www.pythonchallenge.com/pc/def/map.html
题目如下:
还有两段文字提示:
everybody thinks twice before solving this.
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.
题目很简单,就是按英文字母表的顺序,把每个字母都换成对应的后2位的字母,后面这段话翻译过来就是这样的:
I hope you didnt translate it by hand. thats what computers are for. Doing it in by hand is inefficient and thats why this text is so long. Using string.maketrans() is recommended. Now apply on the url.
Python Challenge的闯关规则就是找到下一个题目的url,本题链接是
http://www.pythonchallenge.com/pc/def/map.html ,
要替换的部分是 ‘map‘(其它部分不变),所以按照对应的规则得到下一题的ur是
http://www.pythonchallenge.com/pc/def/ocr.html 。
想记录的原因是接触到一个新的函数:maketrans()
用法如下:
>>> from string import maketrans() >>> inp = ‘koe‘ >>> out = ‘mqg‘ >>> res = maketrans(inp, out) >>> str = ‘pythonchallenge.com/pc/def/map.html‘ >>> print str.translate(res)
输出结果:
pythqnchallgngg.cqm/pc/dgf/map.html
标签:
原文地址:http://www.cnblogs.com/Myoungs/p/5513841.html