Advertisement
felixnardella

Pigreco.py in Python

Mar 14th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. from decimal import *
  2. import time
  3. D=Decimal
  4. print ("Calcolo del Pi greco")
  5. print ("Quante cifre vuoi?")
  6. cifre=input ()
  7. e=int(cifre)
  8. getcontext().prec=e
  9. n=0
  10. pigreco=0
  11. tempo_iniziale = time.time()
  12. while n<1500:
  13. a=D(4)/D(8*n+1)
  14. b=D(2)/D(8*n+4)
  15. c=D(1)/D(8*n+5)
  16. d=D(1)/D(8*n+6)
  17. pigreco=D(pigreco)+D(a-b-c-d)/16**n
  18. n=n+1
  19. simbolo='\u03c0'
  20. print (simbolo, " = ", pigreco)
  21. tempo_finale = time.time()
  22. print ("Calcolate", e, "cifre in", "%1.3f"%(tempo_finale - tempo_iniziale), "secondi.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement