Advertisement
AceScottie

pi

Jul 25th, 2018
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import numpy
  2. import scipy
  3. import math
  4. import sympy
  5. from decimal import *
  6.  
  7. print(math.pi)
  8. print(numpy.pi)
  9. print(scipy.pi)
  10. print(sympy.pi)
  11. r = 5
  12. print(math.pi*(r**2))
  13. print(numpy.pi*(r**2))
  14. print(scipy.pi*(r**2))
  15. print(sympy.pi*(r**2))
  16.  
  17.  
  18. def make_pi():
  19.     q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
  20.     for j in range(1000):
  21.         if 4 * q + r - t < m * t:
  22.             yield m
  23.             q, r, t, k, m, x = 10*q, 10*(r-m*t), t, k, (10*(3*q+r))//t - 10*m, x
  24.         else:
  25.             q, r, t, k, m, x = q*k, (2*q+r)*x, t*x, k+1, (q*(7*k+2)+r*x)//(t*x), x+2
  26.  
  27.  
  28. digits = make_pi()
  29. pi_list = []
  30. my_array = []
  31.  
  32. for i in make_pi():
  33.     my_array.append(str(i))
  34.  
  35. my_array = my_array[:1] + ['.'] + my_array[1:]
  36. big_string = "".join(my_array)
  37. print "here is a pi as a string:\n %s" % big_string
  38. pi = Decimal(big_string)
  39. print("pi is %s" %(Decimal(big_string)))
  40. r = Decimal(5.0000000000000000000000000000000000000000000)
  41. print("now we can do math with pi")
  42. print(Decimal(Decimal(pi)*r**2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement