pythonchallenge_level4

简介: pythonchallenge各关解题

level4

地址:http://www.pythonchallenge.com/pc/def/linkedlist.php
源码:git@code.aliyun.com:qianlizhixing12/PythonChallenge.git。
问题:在页面源码中找出数字替换URL。

#!/usr/bin/env python3
# -*- coding:UTF-8 -*-

# Level 4

import urllib.request
import re

def fun(sid):
    url = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" + sid
    response = urllib.request.urlopen(url)
    body = response.read()
    response.close
    
    body = body.decode("utf8")
    nid = body.split(" ")[-1]
    
    if nid.isdigit():
            return fun(nid)
    elif body == "Yes. Divide by two and keep going.":
        sid = str(int(sid) / 2)
        return fun(sid)
    else:
        return body

if __name__ == "__main__":
    print("Level 4:", fun("12345"))
相关文章
|
索引
PAT (Advanced Level) Practice - 1056 Mice and Rice(25 分)
PAT (Advanced Level) Practice - 1056 Mice and Rice(25 分)
90 0
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
PAT (Advanced Level) Practice - 1068 Find More Coins(30 分)
92 0
PAT (Advanced Level) Practice - 1017 Queueing at Bank(25 分)
PAT (Advanced Level) Practice - 1017 Queueing at Bank(25 分)
109 0
|
Python
pythonchallenge_level7
pythonchallenge各关解题
1131 0
|
Python
pythonchallenge_level8
pythonchallenge各关解题
1402 0
|
Python
pythonchallenge_level11
pythonchallenge各关解题
1044 0
|
Python
pythonchallenge_level6
pythonchallenge各关解题
1108 0
|
Python
pythonchallenge_level5
pythonchallenge各关解题
959 0