欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

pythonchallenge解法源码(6-10)

程序员文章站 2024-02-12 18:12:52
...

第六关

import zipfile

comments = []
num = '90052'
suffix = '.txt'

with zipfile.ZipFile('channel.zip') as zf:
    while True:
        try:
            zi = zf.getinfo(num + suffix) #获取zip文档中指定文件的信息
            comments.append(zi.comment.decode('utf-8'))
            data = zf.read(num + suffix).decode('utf-8') #获取zip文档中分指定文件的二进制数据
            num = data.split(' ')[-1]
        except:
            break
print(''.join(comments))

第七关

import urllib
from PIL import Image

urllib.request.urlretrieve("http://www.pythonchallenge.com/pc/def/oxygen.png","oxygen.png")

with Image.open("oxygen.png",'r') as ig:
    msg = []
    for i in range(0,608,7):
        msg.append(list(ig.getpixel((i,43)))[0])

    answer = ''
    sw = []
    print(msg)
    for i in msg:
        answer += chr(i)

    print(answer)

    l1 = answer[43:-1].split(",")
    for x in l1:
        print(chr(int(x.strip())))

第八关

import requests
import re
import bz2

url = 'http://www.pythonchallenge.com/pc/def/integrity.html'

response = requests.get(url).text
pattern1 = "<!--(.*?)-->"
text = re.findall(pattern1,response,re.S)
print(text)

un = b'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084'
pw = b'BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08'
print(bz2.decompress(un))
print(bz2.decompress(pw))

第九关

from PIL import Image,ImageDraw

img = Image.open('good.jpg')
newImg = Image.new('L',img.size)
draw = ImageDraw.Draw(newImg)
draw.line(first,fill=255)
draw.line(second,fill=255)
newImg.show()

第十关

import re

def describe(s):
    return "".join([str(len(m.group(0))) + m.group(1) for m in re.finditer(r"(\d)\1*", s)])

s = "1"

for dummy in range(30):
    s = describe(s)
print(len(s))

 

相关标签: pythonchallenge