This is an interesting website for learning python, which exercises the level of Python in the form of level. There are 33 levels in total. Each level needs to use Python knowledge to solve the problem, find the answer, and then enter the next level. It is a great test of the comprehensive mastery of Python. For example, some people need regular expressions to break through, and some need crawlers
In general, we learn Python in Chapter order, such as basic syntax, basic data types, conditional statements, circular statements, functions, object-oriented, etc. if the learning time span is too long, it is easy to forget what we learned earlier. At this time, you can take this website to comprehensively test your mastery of python, so as to find out and make up for deficiencies
Now let's talk about how to play this website
It seems that the website has been established for a long time, but it has a long time to see the main page of the website!
Next, we click get challenged to start the challenge
Level 0, antique, hahaha, let's change the url according to the 38th power of 2. This should be regarded as a warm-up exercise. We can calculate it directly through Python
Replace the calculation result with 0 in the url to enter the next level
Next is the official level, and our game officially begins!
According to the letters in the picture and the tips below, we can conclude that moving the front letter back two digits is the back letter
Then, according to this law, recalculate the lowest string of characters
Here we examine the relevant knowledge of string encoding in Python
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.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj.''' def trans(text): new_text = '' for i in text: if str.isalpha(i): n = ord(i) if i >= 'y': n = ord(i) + 2 - 26 else: n = ord(i) + 2 new_text += chr(n) else: new_text += i print(new_text) trans(text)
Output:
i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.
You can see that the author of the website is still very humorous. Hahaha, don't translate manually~
Next, we call the function again and pass in "map" to get the new url
trans("map")
Output:
ocr
At this point, we can enter the next level by replacing the map in the url with ocr
The hint may be in the book, hahaha, this is to see the blind rhythm, or in the web page source code. We right-click to view the source code and pull down to see the green area
Find rare characters in the MES below
It means to find the characters with the least number of occurrences in the following large string of characters
We first use request to request the web page, and then get the characters through regular expressions
import requests def get_challenge(s): return requests.get('http://www.pythonchallenge.com/pc/' + s).text text = get_challenge('def/ocr.html') str = ''.join(text) import re text = re.compile('<!--((?:[^-]+|-[^-]|--[^>])*)-->', re.S).findall(str)[-1] counts = {} for c in text: counts[c] = counts.get(c, 0) + 1 print(counts)
Output:
{'\n': 1221, '%': 6104, '$': 6046, '@': 6157, '_': 6112, '^': 6030, '#': 6115, ')': 6186, '&': 6043, '!': 6079, '+': 6066, ']': 6152, '*': 6034, '}': 6105, '[': 6108, '(': 6154, '{': 6046, 'e': 1, 'q': 1, 'u': 1, 'a': 1, 'l': 1, 'i': 1, 't': 1, 'y': 1}
It can be seen that the last few characters appear the least. Together, they are "equality". Replace the url character ocr to enter the next level
Well, isn't it interesting? We won't continue the spoiler. Interested partners can explore by themselves, which is very helpful to consolidate the basic knowledge of Python!
Website address: http://www.pythonchallenge.com/
Official reference: https://garethrees.org/2007/05/07/python-challenge/