日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

the python challenge_The Python Challenge 谜题全解(持续更新)

發(fā)布時間:2023/12/4 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 the python challenge_The Python Challenge 谜题全解(持续更新) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Python Challenge(0-2)

是個很有意思的網站,可以磨練使用python的技巧,每一關都有挑戰(zhàn),要編寫相應的代碼算出關鍵詞,才可以獲取下一關的url,還是很好玩的QAQ

LEVEL 0

顯然是計算圖片中的\(2^{38}\),結果為274877906944,所以url為http://www.pythonchallenge.com/pc/def/274877906944.html

print(2**38) #輸出274877906944

LEVEL 1

仔細觀察\(K→M,O→Q,E→G\)有什么規(guī)律,結論是后面的字母在字母表中都是前一個的索引加二,比如#\(K\)是第11個,\(M\)是第13個,所以我們也可以得出轉換字符串的方法:

import string

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

l = string.ascii_lowercase + "ab"#每次都是+2,所以后面多加了2個字母,這是小寫字母表

def tran(s):

tmp =""

for i in s:

if i in l:#如果當前處理的字符是字母

id = l.index(i)

tmp += l[id+2]

else:

tmp += i

return tmp

print(tran(a))

#輸出了

"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上試試

顯然,調用一下就把url中的map換成了ocr,得到了下一關的url:www.pythonchallenge.com/pc/def/ocr.html

LEVEL 2

顯然第三關要看清楚圖片上的文字是不可能的,下面提示的文字里面有page source,于是馬上想到查看網頁源代碼,于是看到了如下內容:

然后就是一長串亂碼

任務很顯然,就是要找到下面很長一串代碼中單獨的元素,復制這么長的代碼到ide里也不方便,所以可以用爬蟲

import requests

from collections import Counter

text = requests.get("http://www.pythonchallenge.com/pc/def/ocr.html").text#獲取HTML文檔

final_text = text.split(""

q = Counter(final_text)#對里面的所有字符計數

t = [i for i in q if q[i]==1]#找出只出現(xiàn)一次的字符

print("".join(t))

#輸出了equality

根據輸出的內容很顯然下一個網頁的url為http://www.pythonchallenge.com/pc/def/equality.html

LEVEL 3

有了上一道題的經驗,看了下圖片和文字說明,題目的意思應該是:查找類似\(AAAbCCC\)這種格式的字符串,我果斷查看了一下頁面源代碼,果然有一大堆文本在等著我去處理...

想起了正則表達式!,處理起來輕松多了

import requests

import re

text = requests.get("http://www.pythonchallenge.com/pc/def/equality.html").text

final_text = re.findall("", text, re.DOTALL)[-1]#re.DOTALL表示忽略換行符

ans = "".join(re.findall("[^A-Z]+[A-Z]{3}([a-z])[A-Z]{3}[^A-Z]+",final_text))

print(ans)

#輸出了linkedlist

LEVEL 4

點擊圖片之后發(fā)現(xiàn)url變成了http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345

提示說下一個nothing的值,抱著試試看的態(tài)度接連輸入了幾個,發(fā)現(xiàn)這個linkedlist很長很長,所以寫了如下代碼

import requests

import re

preurl = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="

id = 12345

while True:

url = preurl + str(id)

text = requests.get(url).text

id = text.split(" ")[-1]

print(text)

#運行了一會之后終于出了結果peak.html

下一關的url為http://www.pythonchallenge.com/pc/def/peak.html

LEVEL 5

略坑,peakhell念快點就是pickle了,pickle是python的一個庫,所以編寫代碼如下:

import pickle

from urllib.request import urlopen

import requests

text = pickle.load(urlopen("http://www.pythonchallenge.com/pc/def/banner.p"))

for line in text:

print("".join([k*v for k,v in line]))

輸出結果為channel,所以下一關的url為http://www.pythonchallenge.com/pc/def/channel.html

LEVEL 6

習慣性地打開頁面源代碼,看到zip,下載http://www.pythonchallenge.com/pc/def/channel.zip后打開readme.txt文檔看到

welcome to my zipped list.

hint1: start from 90052

hint2: answer is inside the zip

所以應該是要從90052.txt開始像之前的linkedlist一個個找下去,最后的輸出是

Collect the comments.

翻zipfile的文檔看到zipfile.comments,寫了下代碼

import zipfile, re

file = zipfile.ZipFile("channel.zip")

num = "90052"

comments = []

while True:

content = file.read(num + '.txt').decode("utf-8")

comments.append(file.getinfo(num + '.txt').comment.decode("utf-8"))

print(content)

match = re.search("Next nothing is (\d+)",content)

if match == None:

break

num = match.group(1)

print("".join(comments))

it's in the air. look at the letters.

總結

以上是生活随笔為你收集整理的the python challenge_The Python Challenge 谜题全解(持续更新)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。