Skip to content

Instantly share code, notes, and snippets.

@larry852
Created December 25, 2017 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larry852/61ce2b65206fc07d3a161b2004f1636e to your computer and use it in GitHub Desktop.
Save larry852/61ce2b65206fc07d3a161b2004f1636e to your computer and use it in GitHub Desktop.
Solucion "The Python Challenges el regreso Reto #2: Decimales de Pi"
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