The Python Challenge Level-7 Solution
来源:互联网 发布:淘宝能刷信用卡吗 编辑:程序博客网 时间:2024/04/29 09:11
The Python Challenge Level-7 Solution
先附上我在Github上存放的代码仓库: The Python Challenge
这道题目网页源代码里没有什么别的提示,而图片中有个条形码类似物,那么就需要我们对图片进行处理了。先想办法把条形码读出来,并且转换成可读的文字
#! /usr/bin/env python3# -*- coding: utf-8 -*-from PIL import Imagefrom io import BytesIOimport requestsimgUrl = 'http://www.pythonchallenge.com/pc/def/oxygen.png'img = Image.open(BytesIO(requests.get(imgUrl).content))for i in range(img.width): midPixel = img.getpixel((i,img.height>>1)) print(midPixel)
得到结果以后我们可以发现,条形码中没一条的宽度是7个像素,所以我们可以再处理一下,把相同的条形码rgb值取一个即可。另外还要注意的是,条形码没有覆盖全部的图片,最后无序的rgb值需要删掉,所以改进一下代码
#! /usr/bin/env python3# -*- coding: utf-8 -*-__author__ = 'Yuuki_Dach'from PIL import Imagefrom io import BytesIOimport requestsimgUrl = 'http://www.pythonchallenge.com/pc/def/oxygen.png'img = Image.open(BytesIO(requests.get(imgUrl).content))midPixel = [img.getpixel((i,img.height>>1)) for i in range(0,img.width,7)]code = [r for r, g, b ,a in midPixel if r==g==b]print("".join(map(chr,code)))
得到提示
smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]
再对给出的数字进行处理,就能得到‘integrity’
0 0
- The Python Challenge Level-7 Solution
- The Python Challenge Level-2 Solution
- The Python Challenge Level-6 Solution
- The Python Challenge Level-3 Solution
- The Python Challenge Level-4 Solution
- The Python Challenge Level-5 Solution
- The Python Challenge Level-8 Solution
- The Python Challenge Level-11 Solution
- The Python Challenge Level 0-1 Solutions
- The Python Challenge Level 9-10 Solutions
- Python Challenge 01 Solution
- Python Challenge 02 Solution
- Python Challenge 03 Solution
- Python Challenge 04 Solution
- Python Challenge 05 Solution
- Python Challenge 06 Solution
- Python Challenge 08 Solution
- Python Challenge 09 Solution
- Virtualbox主机和虚拟机之间文件夹共享及双向拷贝(宿主机Windows->Ubuntu 16.04 LTS)
- 第三周项目2-建设“顺序表”算法库
- 《大道至简》第一章读后感
- unity的XML读取
- AngularJS指令详解(4)—指令中的绑定策略
- The Python Challenge Level-7 Solution
- SurfaceView, GLSurfaceView, SurfaceTexture和TextureView
- phpstudy如何创建虚拟主机
- php中几个操作函数参数的函数func_num_args() func_get_args() func_get_arg($i)php
- Spring-4 bean之间的关系----继承和依赖
- 【SSM 3】Mybatis应用,和Hibernate的区别
- Gradle for Android基本理解
- 在一个activity里关闭另外一个activity的方法
- java final关键字