pythonchallenge Level 18

2021/12/7 11:20:11

本文主要是介绍pythonchallenge Level 18,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

第18关地址:http://www.pythonchallenge.com/pc/return/balloons.html

账号:huge 密码:file

查看源码

获得提示信息

标题:can you tell the difference?

提示:it is more obvious that what you might think

两只鹅的亮度不一样,亮度brightness

打开http://www.pythonchallenge.com/pc/return/brightness.html

发现还是鹅(⊙o⊙)…

查看源码,得到提示信息maybe consider deltas.gz

打开https://www.pythonchallenge.com/pc/return/deltas.gz 得到下载文件deltas.gz

看样子是要处理deltas.gz

import gzip

file = open("deltas.txt",'wb')
f = gzip.GzipFile("deltas.gz")
data = f.read()
file.write(data)
file.close()

解压deltas.gz,得到一个deltas.txt,打开是两组数字

使用difflib找不同

import gzip, difflib


file = open("deltas.txt",'wb')
f = gzip.GzipFile("deltas.gz")
data = f.read()
file.write(data)
file.close()

file = open("deltas.txt",'r')
dataA = []
dataB = []
for line in file:
    dataA.append(line[:53]+"\n")
    dataB.append(line[56:])

diff = difflib.Differ().compare(dataA,dataB)

left = open("z_18left.png","wb")
right = open("z_18right.png","wb")
diff_data = open("z_18diff.png","wb")
same_data = open("z_18same.png","wb")
for line in diff:
    flag = line[0]
    line_data = line[1:].strip()
    if len(line_data)!=0:
        bs = bytes([int(o,16) for o in line_data.split(" ") if o])
        if flag == '-':
            # print("仅在左边出现",line_data) # - 仅在左边出现
            left.write(bs)
        elif flag == '+':
            # print("仅在右边出现",line_data)  # + 仅在右边出现
            right.write(bs)
        elif flag == '?':
            # print("存在疑问的",line_data) # ? 存在疑问的
            diff_data.write(bs)
        else:
            # print("相同的",line_data) # 相同的
            same_data.write(bs)

left.close()
right.close()
diff_data.close()
same_data.close()

得到四张图,其中

只在左边出现的生成了:fly

只在右边出现的生成了:butter

相同的生成了:../hex/bin.html

获得下一关地址:http://www.pythonchallenge.com/pc/hex/bin.html

账号:butter 密码:fly



这篇关于pythonchallenge Level 18的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程