当前位置: 首页 > article >正文

python challenge

import string
######## 1 ###############else chr(ord(‘a’)+1-ord(‘z’)+ord(x))

s = “http://www.pythonchallenge.com/pc/def/map.html”

l1 = [chr(ord(x)+2)for x in s if ord(‘a’)<=ord(x) <=ord(‘z’)]

s2 = ‘’.join(l1)

l2 = [chr(ord(x)-26) if x ==’|’ or x == ‘{’ else x for x in s2 ]

s3 = ‘’.join(l2)

print(s3)

############### 4 #################

import requests

import re

ans = “12345”

# key = [‘44827’]

number = re.compile("\d+")

n = 1

while n<401:

r = requests.get(“http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=” + ans)

t = r.text

key = re.findall(number, str(t)) # 返回值为列表

if len(key) == 2:

print(t)

temp_text1 = requests.get(“http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=” + ‘’.join(key[1])).text

temp_num1 = re.findall(number, str(temp_text1))

if temp_num1:

ans = ‘’.join(temp_num1)

print(ans)

else:

temp_text2 = requests.get(“http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=” + ‘’.join(key[1])).text

temp_num2 = re.findall(number, str(temp_text2))

ans = ‘’.join(temp_num2)

print(ans)

elif key:

ans = ‘’.join(key)

print(ans)

else:

print(t)

ans = str(int(ans)/2)

# break

n = n+1

################## 5 ######################

import requests

import re

import pickle

# r = requests.get(“http://www.pythonchallenge.com/pc/def/banner.p”)

# t = r.text

original = “D:\Desktop\python学习\新建文本文档.txt”

destination = “D:\Desktop\python学习\新建文本文档2.txt”

content = ‘’

outsize = 0

with open(original, ‘rb’) as infile:

content = infile.read()

with open(destination, ‘wb’) as output:

for line in content.splitlines():

outsize += len(line) + 1

output.write(line + str.encode(’\n’))

# print(“Done. Saved %s bytes.” % (len(content)-outsize))

f2 = open(‘D:\Desktop\python学习\新建文本文档2.txt’,‘rb’)

l = pickle.load(f2) # 一个列表

print(l)

for t in l:

ans = ‘’

for i in t:

ans = ans + i[0]*i[1]

print(ans)

################### 6 #########################
import requests
import re

import os

import zipfile

ff = zipfile.ZipFile(‘D:\Downloads\channel.zip’)

f2 = open(‘D:\Desktop\python学习\新建文本文档.txt’,‘wb’)

# print(ff.getinfo(‘46145.txt’))

number = re.compile("\d+")

ans = ‘90052’

files = []

for root,dirs,file in os.walk(‘D:\Downloads\channel’):

files = file

w = []

while True:

f = open(‘D:\Downloads\channel\’ + ans + ‘.txt’)

text = f.read()

t = re.findall(number, text) # 返回值是列表

if t:

ans = ‘’.join(t)

# print(ans, text)

k = ff.getinfo(ans+’.txt’).comment

f2.write(k)

# w.append(k)

# print(k)

else:

# print(ans, text)

# w.append(k)

# print(k)

break

f2 = open(‘D:\Desktop\python学习\新建文本文档’,‘wb’)

f2.write(w)

print(w)

####################### 7 #####################

import urllib.request as ur

from PIL import Image

import requests

im_in = open(‘D:\Desktop\python学习\iamge.png’,‘wb’)

r = requests.get(“http://www.pythonchallenge.com/pc/def/oxygen.png”) # 个人觉得是字符串。不是字符串,是response

print(r.content)

im_in.write(r.content)

im_in.close()

im_out = Image.open(‘D:\Desktop\python学习\iamge.png’)

(width,height) = im_out.size

# print(width,height)

pixel1 = im_out.getpixel((0,height/2))

a = pixel1[0]

for i in range(1, width, 1):

pos = (i, height / 2)

# pixel(49,49,49,255)前三位代表的是rgb的值.

pixel = im_out.getpixel(pos)

# ascii码转字符

if pixel[0] == pixel[1] == pixel[2]:

if a != pixel[0]:

print(chr(pixel[0]),end=’’)

a = pixel[0]

else:

continue

print(’ ‘,end=’’)

else:

break

# char = chr(pixel[0])

print(’’.join(map(chr, [105, 110, 116, 101, 103, 114, 105, 116, 121])

################### 8 ####################################

import requests

import re

r = requests.get(“http://www.pythonchallenge.com/pc/def/integrity.html”)

content = r.text

content = re.sub(’\n’,’’,content)

content = re.findall(".* ",content)

s = ‘’.join(content)

un = re.findall(“un: ‘([^’]*)”,s)

print(s)

s2 = ‘’.join(un)

print(s2)

######################## 9 #################################

import requests

from PIL import Image

first = [146,399,163,403,170,393,169,391,166,386,170,381,170,371,170,355,169,346,167,335,170,329,170,320,170,

310,171,301,173,290,178,289,182,287,188,286,190,286,192,291,194,296,195,305,194,307,191,312,190,316,

190,321,192,331,193,338,196,341,197,346,199,352,198,360,197,366,197,373,196,380,197,383,196,387,192,

389,191,392,190,396,189,400,194,401,201,402,208,403,213,402,216,401,219,397,219,393,216,390,215,385,

215,379,213,373,213,365,212,360,210,353,210,347,212,338,213,329,214,319,215,311,215,306,216,296,218,

290,221,283,225,282,233,284,238,287,243,290,250,291,255,294,261,293,265,291,271,291,273,289,278,287,

279,285,281,280,284,278,284,276,287,277,289,283,291,286,294,291,296,295,299,300,301,304,304,320,305,

327,306,332,307,341,306,349,303,354,301,364,301,371,297,375,292,384,291,386,302,393,324,391,333,387,

328,375,329,367,329,353,330,341,331,328,336,319,338,310,341,304,341,285,341,278,343,269,344,262,346,

259,346,251,349,259,349,264,349,273,349,280,349,288,349,295,349,298,354,293,356,286,354,279,352,268,

352,257,351,249,350,234,351,211,352,197,354,185,353,171,351,154,348,147,342,137,339,132,330,122,327,

120,314,116,304,117,293,118,284,118,281,122,275,128,265,129,257,131,244,133,239,134,228,136,221,137,

214,138,209,135,201,132,192,130,184,131,175,129,170,131,159,134,157,134,160,130,170,125,176,114,176,

102,173,103,172,108,171,111,163,115,156,116,149,117,142,116,136,115,129,115,124,115,120,115,115,117,

113,120,109,122,102,122,100,121,95,121,89,115,87,110,82,109,84,118,89,123,93,129,100,130,108,132,110,

133,110,136,107,138,105,140,95,138,86,141,79,149,77,155,81,162,90,165,97,167,99,171,109,171,107,161,

111,156,113,170,115,185,118,208,117,223,121,239,128,251,133,259,136,266,139,276,143,290,148,310,151,

332,155,348,156,353,153,366,149,379,147,394,146,399]

second = [156,141,165,135,169,131,176,130,187,134,191,140,191,146,186,150,179,155,175,157,168,157,163,157,159,

157,158,164,159,175,159,181,157,191,154,197,153,205,153,210,152,212,147,215,146,218,143,220,132,220,

125,217,119,209,116,196,115,185,114,172,114,167,112,161,109,165,107,170,99,171,97,167,89,164,81,162,

77,155,81,148,87,140,96,138,105,141,110,136,111,126,113,129,118,117,128,114,137,115,146,114,155,115,

158,121,157,128,156,134,157,136,156,136]

# second = []

dot = first + second

l = len(dot)

x = [dot[i] for i in range(0, l) if i % 2 == 0]

y = [dot[i] for i in range(0, l) if i % 2 != 0]

ll = len(x)

# r = requests.get(“http://www.pythonchallenge.com/pc/return/good.jpg”)

# content = r.content

# print(content)

# im = open(“D:\Desktop\python学习\image.jpg”, ‘wb’)

# im.write(content)

# im.close()

im = Image.open(“D:\Desktop\python学习\good.jpg”)

w,h = im.size

im2 = Image.new(im.mode,(w,h))

for i in range(0, ll):

# print(i)

im2.putpixel((x[i],y[i]), (255,255,255))

# for i in range(0,50):

# im.putpixel((i, i), (0, 0, 0))

im2.save(‘D:\Desktop\python学习\ans.jpg’)

############### 11 ###########################

import requests

import urllib.request as ur

from PIL import Image

im = Image.open(“D:\Desktop\python学习\cave.jpg”)

(w, h) = im.size

im2 = Image.new(im.mode, (w, h))

for i in range(0, h):

end = w//2

start = 0

for j in range(0, w):

if (i + j)%2 == 0:

pixel = im.getpixel((j,i))

im2.putpixel((end,i),pixel)

end = end + 1

else:

pixel = im.getpixel((j, i))

im2.putpixel((start, i), pixel)

start = start + 1

im2.save(“D:\Desktop\python学习\10ans.jpg”)

################### 12 ###############################
import requests
import pickle
import re

f = open(“D:\Desktop\python学习\evil2.gfx”, ‘rb’)

content = f.read()

for i in range(0,5):

l = content[i::5]

ff = open(f"D:\Desktop\python学习{i}.jpeg",“wb”)

ff.write(l)

#################### 13 #########################

from xmlrpc.client import ServerProxy

server = ServerProxy(“http://www.pythonchallenge.com/pc/phonebook.php”)

response = server.phone(“Bert”)

print(response)

############# 14 #######################

from PIL import Image

im = Image.open(“D:\Desktop\python学习\wire.png”)

(w, h) = im.size

w2 = h2 = 100

im2 = Image.new(im.mode,(w2,h2))

a = 0

b = w2

c = 0

d = h2

n = 0

num = 0

print(im.getpixel((num, 0)))

for j in range(0,w2//2):

n +=1

print(n)

for i in range(a, b):

im2.putpixel((i, c), im.getpixel((num, 0)))

num += 1

for i in range(c+1, d):

im2.putpixel((b-1, i), im.getpixel((num, 0)))

num += 1

for i in range(b-2, a, -1):

im2.putpixel((i, d-1), im.getpixel((num, 0)))

num += 1

for i in range(d-1, c, -1):

im2.putpixel((a, i), im.getpixel((num, 0)))

num += 1

a += 1

b -= 1

c += 1

d -= 1

im2.save(“D:\Desktop\python学习\14ans.png”)

########### 15 ###################

import calendar

from datetime import date

d = date(1006,1,1)

while d.year<1997:

if d.isoweekday() == 4 and calendar.isleap(d.year):

print(d.year)

d = d.replace(year=d.year + 10)

############ 16 ###############

from PIL import Image

im = Image.open(“D:\Desktop\python学习\mozart.gif”)

im2 = im

(w,h) = im.size

for i in range(0,h):

nw = 0

nh = i

j = 0

while j < w:

pixel = im.getpixel((j,i))

if pixel == 195:

start = j + 5

end = j -1

for k in range(start,w):

im2.putpixel((nw,nh),im.getpixel((k,i)))

nw += 1

for kk in range(0,end+1):

im2.putpixel((nw, nh), im.getpixel((kk, i)))

nw += 1

break

j += 1

im2.save(“D:\Desktop\python学习\16ans.gif”)

##################### 17########################

import requests

import re

import http.cookiejar

import urllib .request

from urllib import parse

import bz2

ans = “12345”

# key = [‘44827’]

number = re.compile("\d+")

info = “”

while True:

r = requests.get( “http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=” + ans)

t = r.text

key = re.findall(“the next busynothing is \d+”, str(t)) # 返回值为列表

num = re.findall(number,’’.join(key))

if num:

cookie = http.cookiejar.MozillaCookieJar() # 创建cookiejar的实例来保存cookie

handler = urllib .request.HTTPCookieProcessor(cookie) # 创建一个处理器处理cookie

opener = urllib.request.build_opener(handler) # 创建一个opener,使用opener访问url,就会将网页中的cookie保存到变量cookie中

url = “http://www.pythonchallenge.com/pc/def/linkedlist.php?busynothing=” + ans

res = opener.open(url)

# print(res.read())

for i in cookie:

print(3)

if i.name == “info”:

print(i.value)

info += i.value

ans = ‘’.join(num)

# print(ans)

# print(str(t))

else:

print(str(t))

# ans = str(int(ans)/2)

break

print(info)

# ina = “BZh91AY%26SY%94%3A%E2I%00%00%21%19%80P%81%11%00%AFg%9E%A0+%00hE%3DM%B5%23%D0%D4%D1%E2%8D%06%A9%FA%26S%D4%D3%21%A1%EAi7h%9B%9A%2B%BF%60%22%C5WX%E1%ADL%80%E8V%3C%C6%A8%DBH%2632%18%A8x%01%08%21%8DS%0B%C8%AF%96KO%CA2%B0%F1%BD%1Du%A0%86%05%92s%B0%92%C4Bc%F1w%24S%85%09%09C%AE%24%90”

# ina = ina.replace("+", “%20”)

# ina = parse.unquote_to_bytes(ina)

# ina = bz2.decompress(ina).decode()

# print(ina)

import this

http://www.lryc.cn/news/2413530.html

相关文章:

  • Wifi 破解原理及教程
  • android 炫酷时间轴,这38款超级炫酷的时间轴特效代码案例,总有一款是你需要的...
  • 整理一些博客网站,助力快速搭建个人知识记录平台
  • 百度地图api初次申请及简单应用
  • Dialog.hide() or Dialog.dismiss()?
  • Matlab R2022a安装
  • 【OpenCV图像处理】三、图像的逻辑运算
  • winrar3.93
  • 某东令牌价js加密
  • 解决目前阶段翻译插件Translation谷歌翻译的问题
  • gameloft java 游戏_每一款JAVA游戏都是经典,但只有四款游戏,是90%玩家从小玩到大...
  • 绿坝花季护航,为何如此吸引眼球?
  • Oracle sql 复习题目总结
  • DDD 领域驱动设计落地实践系列:战略设计和战术设计
  • PCI简易通讯控制器驱动的安装办法
  • 【算法】----完全背包问题(动态规划)
  • 编程行业里面的新行话
  • 双重标准? Retina屏科学原理
  • ScriptManager的用法
  • Initialization error Could not initializa “D:\app\Administrator\product\11.2.0\dbhome_1\bin\oci...“
  • 视频转gif图片格式-好用的软件
  • Flash组件按钮的使用详解
  • 程序员怎么学?看完这一篇就够了【非常详细】 从零基础入门到精通!
  • 游戏中的寻路算法研究:关于网格
  • 贱男村001号文件
  • 电脑报网站使用盗版软件?
  • com.android.gallery3d文件夹,如何在Android Gallery3D(cooliris)中显示特定文件夹?
  • VMware虚拟机保姆级安装及使用教程
  • delphi学习总结
  • 事务在触发器中结束。批处理已中止。_Introduction to DDIA amp; 6.824(八):分布式事务...