banovski

Pi

Sep 11th, 2020 (edited)
1,800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import math
  4.  
  5. lowest_value=1
  6.  
  7. for number in range(100, 10001):
  8.     lower_limit = int(number // 3.2)
  9.     upper_limit = int(number // 3.1 + 1)
  10.     for divisor in range(lower_limit, upper_limit):
  11.         division_result = number / divisor
  12.         subtraction_result = division_result - math.pi
  13.         absolute_value = abs(subtraction_result)
  14.         if absolute_value < lowest_value:
  15.             lowest_value = absolute_value
  16.             print(number, "/", divisor, "=", '{0:.9f}'.format(division_result), end="\n")
  17.  
  18. # 100 / 31 = 3.225806452
  19. # 100 / 32 = 3.125000000
  20. # 101 / 32 = 3.156250000
  21. # 104 / 33 = 3.151515152
  22. # 107 / 34 = 3.147058824
  23. # 110 / 35 = 3.142857143
  24. # 179 / 57 = 3.140350877
  25. # 201 / 64 = 3.140625000
  26. # 223 / 71 = 3.140845070
  27. # 245 / 78 = 3.141025641
  28. # 267 / 85 = 3.141176471
  29. # 289 / 92 = 3.141304348
  30. # 311 / 99 = 3.141414141
  31. # 333 / 106 = 3.141509434
  32. # 355 / 113 = 3.141592920
  33.  
Add Comment
Please, Sign In to add comment