Python Challenge, question 4, pythonchallenge
No prompt is displayed for this question. There is only one picture, and there is no name for the picture, so you can directly view the source code. The source code is as follows:
We can see that urllib is used to solve the problem, prompting us not to try noting one by one, because the number is very large, far more than four hundred times (the final proof actually does not need four hundred times, one hundred and twenty times). Since there are so many times, you must not try it manually, but you can allow the computer to automatically access and extract the nothing value. Click the image, we get the first nothing value 44827, and then modify the URL to get the next nothing value, no nothing page will end with this sentence "and the next nothing is" followed by a number (of course, because of the needs of the URL, we understand it as a string, at the beginning, he thought that the number was five digits. Then, four or five digits appeared, and three were later... So I still honestly write the code about extracting the last unlimited number characters) to guess that the content of the page that can get the answer will be different from that, the final code is as follows:
Import urllib. requestname = 'HTTP: // www.pythonchallenge.com/pc/def/?list.php? Nothing = 'finalnum = '000000' # nothing's number stringwhile 1: f = urllib. request. urlopen (name + x) content = f. read (). decode ('utf-8') print (content) # output the page content to facilitate viewing the Final Solution information finalNum = [] content = list (content) content. reverse () for I in content: # present the final numeric character if I. isdigit (): finalNum. append (I) else: break finalNum. reverse () finalNum = ''. join (finalNum) if not finalNum: # judge whether the last content of the page is a numeric character. if not, the loop break will pop out.
The page information at the end of the loop is "Yes. divide by two and keep going ", the previous page is" and the next nothing is 16044 ", so the finalNum value is changed to '123', restart the program, and finally get the answer