Python Challenge5Peak Hell


Title address www.pythonchallenge.com/pc/def/peak…


The subject content pronounce it


The title method

This is a tricky Angle for non-native English speakers.

  • The title of the page ispeak hell
  • The picture is of a mountain, i.epeak
  • Page Text Promptpronounce itLet’s read it out

Linking peak hell, I noticed that it sounds a lot like pickle, a built-in Python module. As usual, looking at the source code of the web page, I found the comment:

<! -- peak hell sounds familiar ? -->
Copy the code

This is also the information that prompts the pickle module. What’s also interesting is that there is an unconventional tag for HTML pages, which is . Looking at the banner. P file, I see garbled characters and conclude that this should be the file stored with the pickle module. Let’s download the file and load it for print.

from urllib.request import urlretrieve
import pickle

url = 'http://www.pythonchallenge.com/pc/def/banner.p'

urlretrieve(url, filename = 'level5.pkl')

with open('level5.pkl'.'rb') as fp:
    result = pickle.load(fp)
    print(result)
Copy the code

It’s printed out as a list of nested lists, with tuples at the bottom. The first element is this: [(‘, 95)] the second element is this: [(‘ ‘, 14), (‘ # ‘, 5), (‘, 70), (‘ # ‘, 5), (“, 1)] the third element is like this: [(” ‘, 15), (‘ # ‘, 4), (‘, 71), (‘ # ‘, 4), (“, 1)] found every element to add up the figures is equal to 95, lenovo, this may be a matrix in front of the number represents the repetition of a single character. Also notice that the banner itself has the meaning of a banner or picture. Then modify the program to print out the contents of the banner.p loop:

from urllib.request import urlretrieve
import pickle

url = 'http://www.pythonchallenge.com/pc/def/banner.p'

urlretrieve(url, filename = 'level5.pkl')

with open('level5.pkl'.'rb') as fp:
    result = pickle.load(fp)

for i in result:
    for j in i:
        print(j[0] * j[1], end = ' ')
    print('\n')
Copy the code

You get a character drawing that sayschannel

Modify the URL address, enter the next level: www.pythonchallenge.com/pc/def/chan…