Created
January 22, 2016 16:35
-
-
Save shionryuu/0e9a6de7178a00420d43 to your computer and use it in GitHub Desktop.
Python Challenge 04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
# http://www.pythonchallenge.com/pc/def/linkedlist.php | |
import urllib, re | |
uri = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s' | |
nothing = '12345' # '8022' | |
pattern = 'and the next nothing is (\d+)' | |
while True: | |
try: | |
content = urllib.urlopen(uri % nothing).read() | |
print content | |
nothing = re.search(pattern, content).group(1) | |
# print nothing | |
except AttributeError: | |
# AttributeError: 'NoneType' object has no attribute 'group' | |
# if you see 'Yes. Divide by two and keep going.', just div | |
# the latest nothing by 2 and try again. | |
break | |
print nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment