Friday, April 15, 2011

Python Challenge level 4

import re
import urllib2

URL = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%i'
direct = 12345

while direct:
    f = urllib2.urlopen(URL % int(direct))
    text = f.readlines()
    direct = ''.join(re.findall('[0-9][0-9]*', ''.join(text)))
    print direct,text
    f.close()



這關實在有點tricky

中間有幾頁傳回的內容數字超多,有些是假的

又有些根本沒數字,直接叫你除以二

所以只能手動改direct來得到結果了

還好也沒跑很多次



Ps.

中間有Infinite loop,真是Tricky...

0 comments:

Post a Comment