I recently saw a very interesting Python game clearance website on the Internet. There are 33 levels in total. Each level requires you to use Python knowledge to solve problems to find the answer, and then enter the next level. It tests the comprehensive mastery of Python. For example, some levels require the use of regular expressions, and some require the use of crawlers.
We usually learn Python in chapter order, packages or modules, and it is easy to forget after learning. You can use this website to comprehensively test your mastery of Python so that you can find and fill in any gaps.
Let’s talk about how to play this website.
This is the main page of the website. It has a sense of history, right? It has been in existence for more than ten years. But don’t underestimate it just because it looks like an antique.
Let's have some fun, click "get challenged" to start the challenge.
Level 0 is the Warming up warm-up session:
The requirement for this level is to modify the URL link, and the prompt given is a mathematical expression on the computer: 2 to the 38th power, So you probably need to calculate the value, and then modify the url to enter the next level.
So this level is a test of basic numerical operations in Python. Do you know how to calculate?
Open Python's own terminal, and you can calculate the result with one line of code:
Replace the 0 in the original link with 274877906944 and press Enter to enter the next page Level 1:
#The game officially begins. The notebook in the picture gives three groups of letters, and it is easy to find the pattern: the letters in front are moved back two places to become the letters in the back.
Then what needs to be done is to decrypt the following prompt string according to this rule and perform displacement decryption to get the real sentence meaning:
This question examines the knowledge related to string encoding and for loops, code The implementation is as follows:
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.''' text_translate = '' for i in text: if str.isalpha(i): n = ord(i) if i >= 'y': n = ord(i) + 2 - 26 else: n = ord(i) + 2 text_translate += chr(n) else: text_translate += i print(text_translate)
Get the result:
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.
The author is very interesting. Of course, you cannot manually calculate it. It is recommended to use string.maketrans() to solve it. What we have adopted above is more direct. method, the official provides a more streamlined method:
import string l = string.lowercase t = string.maketrans(l, l[2:] + l[:2]) print (text.translate(t))
Then change the map in the url to ocr and press Enter to reach the second level:
The author went on to say that the hint may be in the book (of course it is impossible) or it may be in the source code of the web page. Then right-click to view the source code and scroll down to see the green area. Sure enough, the problem is found:
means: find the fewest characters in the following string of characters. Characters
Inspected several knowledge points:
Regular expression to extract string
list counting
Conditional statement
If it were you, what would you do?
Let’s take a look, ten lines of code to quickly implement:
import requests url = 'http://www.pythonchallenge.com/pc/def/ocr.html' res = requests.get(url).text text = re.findall('.*?<!--.*-->.*<!--(.*)-->',res,re.S) # list转为str便于遍历字符 str = ''.join(text) lst = [] key=[] #遍历字符 for i in str: #将字符存到list中 lst.append(i) #如果字符是唯一的,则添加进key if i not in key: key.append(i) # 将list列表中的字符出现字数统计出来 for items in key: print(items,lst.count(items))
First, use Requests to request the web page and then use regular expressions to extract the string, and then use a for loop to count the number of occurrences of each character.
% 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
You can see that the last few characters appear the least, which together are "equality". By replacing the url characters, you can pass the second level and enter the next level to continue the challenge. Isn’t it interesting?
Each subsequent level requires the use of relevant Python skills to solve, such as level 4:
The author of this level made a little prank, You need to manually enter the value into the URL and press Enter. Do you think that's the end of it? It does not constantly pop up new values for you to enter, seemingly endlessly.
所以,这一关肯定不能采取手动输入的方法闯关,自然要用到 Python 了。要实现自动填充修改 url 回车跳转到新 url,循环直到网页再也无法跳转为止这一功能。
如果是你,你会怎么做?
其实,一段简单的爬虫加正则就能搞定。思路很简单,把每次网页中的数值提取出来替换成新的 url 再请求网页,循环下去,代码实现如下:
import requests import re import os # 首页url resp = requests.get( 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345').text url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=' # 计数器 count = 0 while True: try: # 提取下一页动态数值 nextid = re.search('\d+', resp).group() count = count + 1 nextid = int(nextid) except: print('最后一个url为:%s' % nexturl) break # 获取下一页url nexturl = url + str(nextid) print('url %s:%s' % (count, nexturl)) # 重复请求 resp = requests.get(nexturl).text
输出结果如下:
可以看到,最终循环了 85 次找到了最后一个数字16044,输入到 url 中就闯关成功。
如果遇到不会做的题,可以在这里找到参考答案:
中参考文教程:
https://www.cnblogs.com/jimnox/archive/2009/12/08/tips-to-python-challenge.html
官方参考教程:
http://garethrees.org/2007/05/07/python-challenge/
The above is the detailed content of Test your python mastery through game play. For more information, please follow other related articles on the PHP Chinese website!

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.