Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1.     def pI (self, precision = 2):
  2.         bestCharge = 100000000 #utilizes a large number so the conditional statement is always passed
  3.         bestPH = 0
  4.         PH = 0
  5.         r, l = 14, 0
  6.         x = 0
  7.         p = 1 * (10 ** (-1*precision))
  8.         while l <= r:
  9.             mid  = round((l + r)/2,precision)
  10.             thisCharge = self._charge_(mid)
  11.             if abs(thisCharge) < bestCharge :
  12.                 bestCharge = abs(thisCharge)
  13.                 bestPH = mid
  14.             if thisCharge > 0:
  15.                 l = mid + p
  16.             else:
  17.                 r = mid - p
  18.         return bestPH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement