Docsity
Docsity

Prepara tus exámenes
Prepara tus exámenes

Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity


Consigue puntos base para descargar
Consigue puntos base para descargar

Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium


Orientación Universidad
Orientación Universidad


X27663 Slow pi approximation, Ejercicios de Informática

Ejercicio del surge de la clase de informática

Tipo: Ejercicios

2021/2022

Subido el 06/11/2022

Kevin-eebe
Kevin-eebe 🇪🇸

7 documentos

1 / 1

Toggle sidebar

Esta página no es visible en la vista previa

¡No te pierdas las partes importantes!

bg1
Write a function slow_pi_approx(n) that given a non negative integer n
computes 4k = 0n (1)k/2k + 1 The returned value has to be rounded to the
ten thousandth by using the python function round(_,4).#
def slow_pi_approx(n):
'''
>>> slow_pi_approx(10)
3.2323
>>> slow_pi_approx(100)
3.1515
>>> slow_pi_approx(1000)
3.1426
'''
total = 0
for x in range(n+1):
total += ((-1)**x)/(2*x+1)
return round(4*total,4)
if __name__ == '__main__':
import doctest
print(doctest.testmod())

Vista previa parcial del texto

¡Descarga X27663 Slow pi approximation y más Ejercicios en PDF de Informática solo en Docsity!

Write a function slow_pi_approx(n) that given a non negative integer n

computes 4∑ k = 0 n (−1) k /2 k + 1 The returned value has to be rounded to the

ten thousandth by using the python function round(_,4).

def slow_pi_approx(n): _'''

slow_pi_approx(10)

slow_pi_approx(100)

slow_pi_approx(1000)

'''_ total = 0 for x in range(n+1): total += ((-1)x)/(2x+1) return round(4total, 4 ) if name == 'main': import doctest print(doctest.testmod())