Created
December 25, 2017 03:31
-
-
Save larry852/61ce2b65206fc07d3a161b2004f1636e to your computer and use it in GitHub Desktop.
Solucion "The Python Challenges el regreso Reto #2: Decimales de Pi"
This file contains 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
from urllib.request import urlopen | |
def pi(posicion, cantidad=None): | |
if 0 < posicion < 100000: | |
posicion -= 1 | |
else: | |
return None | |
cantidad = posicion + 1 if cantidad is None else posicion + cantidad | |
html = str(urlopen('http://www.geom.uiuc.edu/~huberty/math5337/groupe/digits.html').read()) | |
# inicio = html.index("3.") + 1 --> 342 | |
# final = html.index("<p><hr><p>") --> 102909 | |
html_decimales = html[342:102909] | |
str_decimales = ''.join(filter(str.isdigit, html_decimales)) | |
return int(str_decimales[posicion:cantidad]) | |
if __name__ == "__main__": | |
# Hacer las pruebas del scrip | |
# en este bloque para no interferir | |
# con la calificación del bot | |
pi(1) # ejemplo de llamada a la función |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment