Python challenge 1-16

Source: Internet
Author: User

At the beginning, I learned python. Listen to the recommendations of senior colleagues and play with Python challenge.

Actually, you can use various languages, but when you finish reading others' answers, you will find how simple and elegant python is.

Although there are not many questions, but after reading the ideas, the source code in this article is self-written.

0th off

Http://www.pythonchallenge.com/pc/def/0.html

2 ** 38

Level 1

Http://www.pythonchallenge.com/pc/def/274877906944.html

Import string

Before = list [String. ascii_lowercase]
After = [CHR (ord (c) + 2) for C in before]
After [before. Index ('y')] = 'A'
After [before. Index ('Z')] = 'B'

Trans = Str. maketrans (''. Join (Before),''. Join (after ))

TEXT = "G fmnc WMS bgblr rpylqjyrc gr ZW fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb GQ glcddgagclr ylb rfyr 'q UFW rfgq rcvr gq qm jmle. sqgle qrpgle. kyicrpyscsi () GQ pcamkkclbcb. LMU ynnjw ml rfc spj. """

Text. Translate (trans)
"Map". Translate (trans)

Level 2

Http://www.pythonchallenge.com/pc/def/ocr.html

Import string

# Copy the final comments from the source code of the webpage with garbled characters
TEXT = """..................."""

Text_list = List (text)

Text_real = []
For C in text_list:
If C in string. ascii_letters:
Text_real.append (c)

''. Join (text_real)

Level 3

Http://www.pythonchallenge.com/pc/def/equality.html

It is not difficult to learn the python regular expression.

TEXT = """........"""

Import re

# Note exactly!
Re. findall ('[^ A-Z] [A-Z] {3} ([A-Z]) [A-Z] {3} [^ A-Z]', text)

Level 4

Http://www.pythonchallenge.com/pc/def/linkedlist.html

I followed the image twice and I knew it ...... Programming ......
Network Programming, from

Http://www.pythonchallenge.com/pc/def/linkedlist.php? Nothing = 40961 start

It will be interrupted once ...... Because the webpage content becomes
Yes. divide by two and keep going.
Manually enter the next number to continue
My first version of the program ended at 82682 again. The content is
There maybe misleading numbers in the text. One example is 82683. Look only for the next nothing and the next nothing is 63579
Change to the current version until the end

From urllib. Request import urlopen
Import re
Template = r "http://www.pythonchallenge.com/pc/def/linkedlist.php? Nothing = {0 }"
Number = 63579
While true:
Url_file = urlopen (template. Format (number ))
Line = List (url_file.readlines () [-1]. Decode ()
Words = line. Split ()
Number = int (words [-1])
Print (number)

Level 5

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

Check that the source code has banner. P, always prompting peakhell ...... Pronounce it ...... Not understood
Then I saw the prompt that I needed to use pickle ......
The rest should be difficult.

From urllib. Request import urlopen
Import pickle

Banner = urlopen (R "http://www.pythonchallenge.com/pc/def/banner.p ")
List_list = pickle. Load (banner)
Banner. Close ()

File = open ("banner.txt", "W ")

Buf = ""
For lst in list_list:
For char, num in lst:
BUF + = char * num
BUF + = '\ N'

File. Write (BUF)
File. Close ()

It's strange that I can execute this code in a sentence in the python shell. writing a script cannot be executed directly. I don't know why ......

Level 6

Http://www.pythonchallenge.com/pc/def/channel.html

Http://www.pythonchallenge.com/pc/def/zip.html

Stuck again ...... Baidu again

This is really ...... Download http://www.pythonchallenge.com/pc/def/channel.zipran and then click the fourth key.

Num = 90052
Filename = r "channel/audio 02.16.txt"

While true:
With open (filename. Format (Num) as file:
Line = file. Readline ()
Num = int (line. Split () [-1])
Print (Num)

Finally, catch collect the comments ...... Baidu, again, found to collect comments of all files in the zip package.
Now used, and finally formed the character painting
The modified code is as follows:
Import zipfile

ZF = zipfile. zipfile ("channel.zip ")
Num = 90052
Out = ""
While true:
Line = ZF. Read ("bytes 02.16.txt". Format (Num ))
Out + = ZF. getinfo ("Export 02.16.txt". Format (Num). Comment. Decode ()
# Print (Num)
Try:
Num = int (line. Split () [-1])
Failed t valueerror:
Print (out)
Break

Level 7

Http://www.pythonchallenge.com/pc/def/oxygen.html

When you look at the image, you will know that the password is on the image, but there is no research on the image ...... Decisive Baidu ......
The code is no longer stuck, and the answer is skipped. After all, I don't want to look at the image at all.

Level 8

Http://www.pythonchallenge.com/pc/def/integrity.html

The bee can click it. the user name and password are required. Obviously, the last two lines of the web page UN and PW should be encrypted.
Make sure that Baidu ...... Bz2 Encryption
Code is too small ......
Import bz2

UN = 'bzh91ay & Sya \ xaf \ x82 \ r \ x00 \ x00 \ x01 \ x01 \ X80 \ x02 \ xc0 \ x02 \ x00 \ x00! \ X9ah3m \ x07 <] \ xc9 \ x14 \ xe1ba \ x06 \ xbe \ x084'
PW = 'bzh91ay & Sy \ x94 $ | \ x0e \ x00 \ x00 \ x00 \ x81 \ x00 \ x03 $ \ x00! \ X9ah3m \ x13 <] \ xc9 \ x14 \ xe1bbp \ x91 \ xf08'
Print bz2.decompress (UN)
Print bz2.decompress (PW)

Nice Python

Level 9

Http://www.pythonchallenge.com/pc/return/good.html

The points and source code on the image tell us that it is an image problem. Although I don't want to, I can only use Baidu.
Import image, imagedraw
IMG = image. New ('rgb ', (640,480 ))
Draw = imagedraw. Draw (IMG)
Draw. Line (first)
Draw. Line (second)
IMG. Show ()
I admire python in another level ......
Finally, Bull

Okay, first come here.
Python is mainly used for text processing and small scripts. You can check the network. Graphics, compression is really not too concerned.
Continue when you are free ~

10th off

Http://www.pythonchallenge.com/pc/return/bull.html

The rule is found by Baidu ...... The latter is a combination of the number of each digit of the previous number and the number of values.

A = ['1']

I = 0
While I <31:
J = 0
Counter = 0
Buf = ""
While j <Len (A [I]):
If J = 0 or a [I] [J] = A [I] [J-1]:
Counter + = 1
J + = 1
Else:
BUF + = STR (Counter) + A [I] [J-1]
Counter = 1
J + = 1
BUF + = STR (Counter) + A [I] [J-1]
A. append (BUF)
I + = 1
# Print (BUF)

Print (LEN (A [30])

After reading the answer, I found that a small function is very beautiful.
Def describe (s ):
Sets = Re. findall ("(1 + | 2 + | 3 +)", S) # Like "111", "2 ",...
Return =. Join ([STR (LEN (x) + X [0] for X in sets])

11th off

Http://www.pythonchallenge.com/pc/return/5808.html

Image processing ...... Skipped,
Password edevil

12th off

Http://www.pythonchallenge.com/pc/return/evil.html

Images, but they have little to do with image processing.
The method is to open an image file and there is one file every five units. Get 5 images.
The last word is useless.
Dis, Pro, port, ional, ity (striked out)
Password disproportional
It's strange that this question doesn't look at how others suggest doing it. Why is it 5? Why not use the last image?

Then Baidu ...... I found this question awesome ...... Answers from awesome people are more detailed.

Http://bochengwen.iteye.com/blog/719082

Bcw104 always answers to the 16th off...
Python challenge is getting boring. I just want to practice python. So I later checked his blog and skipped it if I was not interested.

13th off

Http://www.pythonchallenge.com/pc/return/disproportional.html

I am not interested in using the Python XML library for processing. See the blog of bcw104.

14th Image Processing
I now admire Python and the author of Python challenge as well as the blogger for using the date processing function 15th ......
16th off or image processing

Ah ...... I can't stand it anymore. I don't know whether it's image processing,

Bcw104 is not updated, and my interest in Python challenge is diminished. Currently, I just want to use it for text processing.

Continue later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.