codeblock

2016年3月28日 星期一

Python Challenge level 5

http://www.pythonchallenge.com/pc/def/peak.html

- Pronounce "peak hell". What?? I pronounced it in my room, and nothing happened...
- Google "peak hell", it turns out to be "pickle."
- See also: https://docs.python.org/2/library/pickle.html
- The target that should be pickled is banner.p (showed in the source page)
- Use pickle.load() to show the content
import urllib
import pickle
link = urllib.urlopen("http://www.pythonchallenge.com/pc/def/banner.p")
web_content = link.read()
link.close()
content = pickle.loads(web_content)
- The content is a 2D array, each element is a tuple including a character and a number, like "('#', 3)"









- Observe that the sum of numbers in the same line are all 95 -> print as a picture!
f = open("result.txt", 'w')
for i in content:
 for j in i:
  for k in range(j[1]):
   f.write(j[0])
 f.write("\n")
- The result is the answer, it's just like:

沒有留言:

張貼留言