pythonchallenge_level7

简介: pythonchallenge各关解题

level7

地址:http://www.pythonchallenge.com/pc/def/oxygen.html
源码:git@code.aliyun.com:qianlizhixing12/PythonChallenge.git。
问题:使用PIL对象观察打印。

#!/usr/bin/env python3
# -*- coding:UTF-8 -*-

# Level 7

import os
import urllib.request

filename = "oxygen.png"
url = "http://www.pythonchallenge.com/pc/def/" + filename
response = urllib.request.urlopen(url)
body = response.read()
response.close

if os.path.exists(filename): os.remove(filename)
tmppng = open(filename, "wb")
tmppng.write(body)
tmppng.close()

import PIL.Image
import re

pim = PIL.Image.open(filename).convert("L")
mid = (pim.size[1] + 1) / 2
stim = []
for x in range(0, pim.size[0], 7):
    stim.append(chr(pim.getpixel((x, mid))))
stim = re.findall("[^0-9]([0-9]{2,3})[^0-9]", "".join(stim))
stim = list(map(int, stim))
stim = list(map(chr, stim))

print("Level 7:", "".join(stim))

if os.path.exists(filename): os.remove(filename)
相关文章
|
索引
PAT (Advanced Level) Practice - 1056 Mice and Rice(25 分)
PAT (Advanced Level) Practice - 1056 Mice and Rice(25 分)
90 0
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
92 0
PAT (Advanced Level) Practice - 1017 Queueing at Bank(25 分)
PAT (Advanced Level) Practice - 1017 Queueing at Bank(25 分)
109 0
|
Python
pythonchallenge_level0
pythonchallenge各关解题
1123 0
|
Python
pythonchallenge_level8
pythonchallenge各关解题
1402 0
|
Python
pythonchallenge_level12
pythonchallenge各关解题
1198 0
|
Python
pythonchallenge_level6
pythonchallenge各关解题
1108 0
|
Python
pythonchallenge_level2
pythonchallenge各关解题
1101 0

热门文章

最新文章