自從自學(xué)了python,除了寫了一些簡單的自動化腳本還沒有實(shí)際應(yīng)用過,于是想通過pythonchallenge闖關(guān)提升python使用的熟練度。
網(wǎng)址:http://www.pythonchallenge.com/
點(diǎn)擊開始挑戰(zhàn),進(jìn)入第0關(guān)。
第0關(guān)
鏈接:http://www.pythonchallenge.com/pc/def/0.html
關(guān)卡序號挺有意思,都是按照計(jì)算機(jī)的編號方式,從0開始的。

這關(guān)比較簡單,2的38次方,通過python交互模式計(jì)算2**38即可。
C:\Users\admin>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 2**38
274877906944
計(jì)算的數(shù)值274877906944將第0關(guān)鏈接http://www.pythonchallenge.com/pc/def/0.html中的0替換,回車進(jìn)入第1關(guān)。
第1關(guān)

思路:這一關(guān)規(guī)律也比較好找,通過圖片可以發(fā)現(xiàn),每個后面的字母在字母表中的順序比前面多兩位,那么先把下面的一串字母轉(zhuǎn)換。轉(zhuǎn)換可以通過ASCII編碼,但要注意y和z。
上代碼:
str1 = "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."
str2 = ''
for i in str1:
if i.isalpha() and i != 'y' and i != 'z':
i_ascii = ord(i)
j_ascii = i_ascii + 2
j = chr(j_ascii)
str2 = str2 + j
elif i == 'y':
j = 'a'
str2 = str2 + j
elif i == 'z':
j = 'b'
str2 = str2 + j
else:
j = i
str2 = str2 + j
print(str2)
得到結(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.
根據(jù)提示,要將這個轉(zhuǎn)換規(guī)則應(yīng)用于url,得到第2關(guān)的地址http://www.pythonchallenge.com/pc/def/map.html
根據(jù)提示,建議使用string.maketrans()方法。用maketrans()方法比較簡單,我使用ASCII碼轉(zhuǎn)換復(fù)雜了很多。