Advertisement
FelipeNeto2

PI (Python)

Dec 13th, 2019
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. import math
  2.  
  3. def truncate(number, digits):
  4.     stepper = pow(10.0, digits)
  5.     return math.trunc(stepper*number)/stepper
  6.  
  7. n = int(input("Entre com o número n: "))
  8.  
  9. aux = 2*10**n
  10.  
  11. soma = 0
  12. for i in range(aux+1):
  13.     termo = (4*(-1)**i)/(2*i+1)
  14.     soma += termo
  15.  
  16. ad = truncate(soma, n)
  17.  
  18. print("O valor da aproximação é {}".format(ad))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement