Python趣味挑战

By 刘志军 , 2019-02-22, 分类: Python

python

pythonchallenge.jpg

有个牛逼的网站叫 www.pythonchallenge.com ,它是一个在线的 Python 技术挑战平台,一共有33道关卡,你只有正确回答了第一道题才能看到第二道题,依此类推

第一次使用这个网站估计你弄不明白怎么玩,因为每道题就是一张图,你要根据每道题的提示信息算出正确答案,正确答案就是下一道题的入口

第一题

calc.jpg

这道题只能算是一道热身题,下面有一行提示,"Hint: try to change the URL address."

它的答案其实就是将2的38次方的结果作为下一道题的入口链接,因为 2**38 等于 274877906944,所以第二道题的链接地址就是将这道题的链接

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

替换成:

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

第二题

打开链接后会重定向到新的页面,出现的图是:

WX20190219-012111@2x.png

图中提供的信息应该是类似于凯撒加密,K->M,O->Q,E->G,也就是意味着每个字母都往右移了2位,可以猜到 a->c,c->e,... x->z, y->a,z->b,另外还有一串加密的提示信息,为了得到正确,答案,我们必须将这串字符串解密出来

先用代码实现可以得到解密算法:

def decrypt(c):

return chr(((ord(c) + 2) - ord('a')) % 26 + ord('a'))

将加密字符串进行解密得到:

>>> s = """



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.



"""

>>> result = ""

>>> for c in raw:

...     if c >= 'a' and c <= 'z':

...         result += decrypt(c)

...     else:

...         result += c

最后解密出result为:

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.

它告诉我们不要等手动的去转换,而是用一种算法来实现,因为遇到很长的字符串时手动转换的效率不高,另外它还给了我们另一种方法就是使用 string.maketrans() 进行转换,所以就有了第二种解法:

>>> t = str.maketrans("abcdefghijklmnopqrstuvwxyz", "cdefghijklmnopqrstuvwxyzab")

>>> s.translate(t)

"i hope you didnt translate it by hand. thats what computers are for. doing itin by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url."

我们将该算法应用到该url

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



将被转换成



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

该链接就是第三题的入口

第三题

WX20190220-075935@2x.png

这道题留给大家思考,第一个答案的将获得一本和Python相关的书籍。

http://www.pythonchallenge.com/

https://github.com/zhiwehu/Python-programming-exercises/blob/master/100%2B%20Python%20challenging%20programming%20exercises.txt

https://www.hackingnote.com/en/python-challenge-solutions/level-1


关注公众号「Python之禅」,回复「1024」免费获取Python资源

python之禅

猜你喜欢

2015-06-17
如何在Python中正确使用static、class、abstract方法
2020-06-13
python 中 xml 转换为 json
2017-12-26
5个酷毙的Python工具
2020-06-01
最新抖音去水印解析
2017-05-15
一步一步教你认识Python闭包
2022-03-13
从一段小代码开始学习如何重构
2013-10-30
Python“不为人知的”特性
2020-06-04
如何用Python执行linux命令
2020-06-07
python合并两个字典
2019-03-09
30个Python 小例子,帮你快速上手Python