python challenge 7网址:www.pythonchallenge.com/pc/def/oxygen.html
从图片一看就发现图片中间有灰色的东西,这时候就想到是不是需要用python的图片模块来出来这段灰色的地方,这里可能是解题的关键,python处理图片比较好的模块是PIL。将全幅图像转换为灰度值后,对中间的那条带子隔7取1。
代码如下:
import PIL.Image temp=PIL.Image.open('D:oxygen.png') #把图片拷贝到本地 temp2=temp.convert('L').getdata() beginpoint=temp.size[0]*50 endpoint=beginpoint+608 ra=range(beginpoint,endpoint,7) temp3=[] for v in ra: temp3.append(chr(temp2[v])) print ''.join(temp3) test=[105, 110, 116, 101, 103, 114, 105, 116, 121] answer='' for line in test: answer=answer+chr(line) print answer