The Python Challenge(2)

问题链接

问题链接如下:

http://www.pythonchallenge.com/pc/def/map.html

答案链接

答案链接如下:

http://www.pythonchallenge.com/pc/def/ocr.html

解题思路

将页面给定的字符串根据给定规则进行替换即可,规则如下:

K -> M
O -> Q
E -> G

转换代码如下:

msg = "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."

for c in msg:
    if c <= 'z' and c >= 'a':
        if chr(ord(c)+2) > 'z':
            c = chr(ord(c)-24)
        else:
            c = chr(ord(c)+2)

    print(c, end='')
print('')

输出信息为:

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.

根据提示,将url中的map进行转换,得到map,则为最终的答案链接。

你可能感兴趣的:(The Python Challenge(2))